User-Agent - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: User-Agent (/showthread.php?tid=58288) |
User-Agent - El Forum - 05-30-2013 [eluser]WebDevB[/eluser] Hi Guys, I've got a problem with the user-agent... It just ignores the code and show's the first IF statement, here is the code: Code: $this->load->library('user_agent'); Cheers guys! User-Agent - El Forum - 05-30-2013 [eluser]TheFuzzy0ne[/eluser] [quote author="WebDevB" date="1369927430"] It just ignores the code and show's the first IF statement, here is the code: [/quote] Sorry, but what does that even mean? What code does it ignore, and what do you mean when you say it "shows the first IF statement"? User-Agent - El Forum - 05-30-2013 [eluser]WebDevB[/eluser] Sorry, I was probably rushing... What seems to happen is if you come from a mobile to the site it ignores the below if statement and loads the first if view... Code: if ($this->agent->is_mobile()) { Is that any better? User-Agent - El Forum - 05-30-2013 [eluser]TheFuzzy0ne[/eluser] CodeIgniter uses the values in ./application/config/user_agents.php to figure out whether or not it's communitcating with a mobile device. If your if-statement is not executing, there's a good chance the mobile device you are using is not in there. Something like this might help you figure out what you need to know about the device in question: Code: foreach (array('agent_string', 'mobile', 'browser', 'version', 'platform') as $val) It's untested, but should do the trick. User-Agent - El Forum - 05-30-2013 [eluser]TheFuzzy0ne[/eluser] Also, an observation on the code you posted. It might be wise to extend the Loader, and override the view() method. You can add a little logic in there that will automatically append '_mobile' to the end of the filename string if it's a mobile request, but only if the mobile view file exists. If not, then it can just fallback on the regular view, and if that's not available, CodeIgniter can just chuck a wobbler as normal. I just thought it might save you from repeatedly having to type: Code: if ($this->agent->is_mobile()) { Instead you'd just type: Code: $this->load->view('some/view', $data); User-Agent - El Forum - 05-30-2013 [eluser]WebDevB[/eluser] Thanks for the reply!! Yea it must be something to do with the user-agent library as this works ok: Code: if(strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') || strstr($_SERVER['HTTP_USER_AGENT'],'iPod')) I will have another look now... User-Agent - El Forum - 05-30-2013 [eluser]CroNiX[/eluser] I see you loading the library as "user_agent", which is the default, but then try to use $this->agent instead of $this->user_agent. It's not "ignoring" the user agent library; you aren't referencing the user_agent object correctly. Are you not getting errors on that? |