Welcome Guest, Not a member yet? Register   Sign In
Switching controllers depending on the version of the site: mobile or desktop
#1

Hello!

How do I switch to a controller for a mobile version of the website in the router?

$this->load->library('user_agent');

if ($this->agent->is_mobile()==TRUE)
{
$route['default_controller'] = "m/index";
} else
{
$route['default_controller'] = "index";
}

The error I'm getting is Undefined property: CI_Router::$load

As far as I understand Loader class is loaded after the Router class, so $this->load doesn't exist yet.

I need to use for the mobile version of the controller which is the controller functionality from the desktop version.

I need to switch between controllers, and not just between views.

How can I do this?
Reply
#2

(This post was last modified: 01-09-2016, 04:05 AM by arma7x. Edit Reason: Typo )

Why not using redirect() in your controller. If you have MY_controller you can put it there instead of adding to each method in every controller.
Keep calm.
Reply
#3

(01-09-2016, 04:02 AM)arma7x Wrote: Why not using redirect() in your controller. If you have MY_controller you can put it there instead of adding to each method in every controller.

Yes, I have a MY_controller.
However, I do not quite understand you. How can I do in MY_controller to switch between the desktop controller and mobile controller?
If not difficult, write please the code to make it clearer.

In routes to select the required controller depending on the version of the site I guess is quite logical. Because the controller still does not boot, including MY_controller. However, as I wrote in the message, there are difficulties with the definition of the mobile version, because unable to load user_agent library.
Reply
#4

Try this

$CI =& get_instance();


$CI->load->library('useragent');
          Heart  love codeigniter Heart
          Learning  best  practices
     Rate my post if you found it helpfull
Reply
#5

Why not have a responsive design? You really want to maintain 2 versions of the site?
Reply
#6

(This post was last modified: 01-12-2016, 05:07 AM by PaulD. Edit Reason: Added PS )

It is a massive dilema with mobile devices, especially when it comes to image sizes etc and reducing the load on mobile sites. Responsive design is problematic to that extent because even a hidden div or a 'do not display' media setting still downloads the image. It is also a conundrum that to cater for mobile sites you need to increase your filesizes like CSS files and HTML files.

I have tried detecting source device before but that in itself is problematic, and as skukbad rightly points out, maintaining two sites is a nightmare too.

However, all my sites for a while now, I have just done as responsive designs, and there has been no problems reported. I think most people browse over a broadband connection anyway these days, rarely browsing via mobile networks.

The one site I tried separate content for detecting the source device, ended up with 3 versions, desktop, mobile and blackberry. It turned into a nightmare and I am pretty certain I would never go down that path again.

Just my opinion of course. Hope that helps,

Paul.

PS I still struggle with large tables, that are such a pain to make responsive on a mobile phone without a scroll bar appearing. That is probably the only headache I have now.
Reply
#7

Does every pages in your web have it own mobile version??
Keep calm.
Reply
#8

Hi, It did on that site where I tried it.

It was a 15-20 page site selling one product range. Some of the pages had games on them, some of them quizzes, all of them geared to selling the brand idea.

I presume you are asking about the site that detected the device and delivered different content depending on the device.

BUT, it was a nightmare. Don't do it!!! Responsive design, despite it's issues, is nearly always good enough IMHO.

Best wishes,

Paul.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB