user3744738
user3744738

Reputation: 19

Codeigniter loading different controllers for mobile

I am looking for solution how to load different controllers not changing website uri for mobile devices. For example I'm going to www.site.com via PC and I should see webpage (works by default, everything is ok). But now I'm going www.site.com via mobile and I want to see mobile version of this website not changing url's. So when I will go to www.site.com/article-123 via mobile, I want to see mobile version of page. I'm looking for solution, but I haven't found anything. I tried to load user_agent library to my routes file, but nothing happened (wanted to change call to controllers for mobile devices). Is there any solution?

Upvotes: 0

Views: 432

Answers (1)

Sparky
Sparky

Reputation: 98758

Quote OP:

"I tried to load user_agent library to my routes file, but nothing happened."

I don't know how you'd add a library to the routes since you never showed us, but see the documentation for proper usage of the user_agent library. Then use the url helper to redirect to a different Controller function.

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

if ($this->agent->is_mobile())
{
    redirect('/mobile/home/', 'refresh'); // go to 'mobile' controller, 'home()' function
}
else
{
    redirect('/desktop/index/', 'refresh'); // go to 'desktop' controller, 'index()' function
}

Upvotes: 1

Related Questions