I’m pretty new to code igniter.
Is there best practice for serving different view for different context.
For example, I’d like to serve specific pages for mobile user agents with the same controllers.
I’m pretty new to code igniter. Is there best practice for serving different view
Share
There isn’t a hard rule for this. You can structure your view files however you like, and call
$this->load->view()to load different view files for different outcomes in your controller. From my experience, CodeIgniter adapts very openly to how you organize your application’s files.In your example, perhaps I’d divide my
system/application/viewsfolder into two subfolders:mainfor desktop browsers, andmobilefor mobile browsers:In an early part of your controller, say the constructor, you can decide what user agent is requesting it and then pick
mainormobilebased on that, then show your views accordingly from your controller actions.Some quick code snippets to give you a better idea since you’re new…
And some helpful references for you to explore:
Hope my explanation helps, and hope you have fun with CodeIgniter 🙂