default controller route for mobile |
My site that uses a mobile subfolder in my controllers and views directories to serve up a mobile friendly version when a user logs in from a phone. The login controller makes that determination when the user logs in, and utilizes the appropriate controllers and view. That works fine. However, when a user navigates away from the site and then attempts to hit mysite.com again, the $route['default_controller'] sends them to 'home', which is the normal version of the site. Is it possible to have a conditional statement in the routes.php file that checks if the user is on mobile and then sets the default_controller, or is there a better way to approach this problem? Thanks!
This sounds wrong. To do a mobile version you want only one view, for mobile, and desktop, and not multiple views. You then use stylesheets to style the page differently for mobile and desktop.
Website: http://tomaz.lovrec.eu
GitHub: https://github.com/slax0rr Twitter: https://twitter.com/slax0rr
Not necessarily. While it is good to have a responsive site (which is styled differently for different devices/screen sizes), you can also have a separate view completely for the mobile site (if it's drastically different).
However, you should be doing this either by having a separate mobile subdomain or similar (m.example.com) or by detecting device on the server side (if you can reliably) and serving the appropriate view (but still using the exact same routes). It really depends on your requirements.
The mobile site is drastically different and only has limited functionality compared to the full site. I ended up modifying my 'home' controller to detect the device the user is on and then redirect them to the 'homemobile' controller if necessary. I also ended up adding a method to force the mobile site into desktop view if that's what the user wants to do, which was the catalyst for this issue.
FYI I ended up using the php script from here: http://detectmobilebrowsers.com And it works brilliantly. Thanks for the replies.
If you have chosen to go this path, then I would advise you move your "mobile detect" piece of code into your base controller(MY_Controller), and have all your controllers extend from it. This way no matter to which URL the user will navigate, your system will check for a mobile device and redirect accordingly.
Website: http://tomaz.lovrec.eu
GitHub: https://github.com/slax0rr Twitter: https://twitter.com/slax0rr
While I'm not a big fan of redirecting mobile browsers and limited functionality on mobile, CI's User_agent library should be perfectly capable of detecting mobile browsers.
PHP Code: if ($this->agent->is_mobile()) |
Welcome Guest, Not a member yet? Register Sign In |