Welcome Guest, Not a member yet? Register   Sign In
Mobile website
#1

[eluser]Unknown[/eluser]
Hi

I'm trying to create a mobile version of my site.
I created separate controller for this, but have no idea how to redirect to it.

So what would be the best way to check for user agent and then load the appropriate controller ?

Thanks!
#2

[eluser]JHackamack[/eluser]
I've developed a few full sites that have a mobile view to them. You'll first off want to figure out which mobile devices you are targeting: iPads, iPhones, Android Phones, etc. Figuring out those will give you a good indication of how to deal with checking. I wanted just iPhones so I used PHP to search for the user agent of the browser:

Code:
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod'))
{
    header('Location: http://yoursite.com/iphone');
    exit();
}
This allows me to redirect the user to a new site, or in your case a new controller.
#3

[eluser]kkristo[/eluser]
You need read http://ellislab.com/codeigniter/user-gui...agent.html

if ($this->agent->mobile() == TRUE){
$this->load->view('mobile/index');
}else{
$this->load->view('index');
}

You don't need do two different controller. But need do different views!
#4

[eluser]Unknown[/eluser]
I figured it out. I extended controller core class, check for user_agent then load appropriate controller.
If there's a better way let me know.

I created separate controller because main controller loads too much resources.




Theme © iAndrew 2016 - Forum software by © MyBB