[eluser]Jonathan Ledbetter[/eluser]
I'm trying to figure out the best way to reroute input for cell phones and Wii. (I've already whipped up a couple of custom methods, isMobile() and isConsole(), in a helper function for this purpose.) Using these three functions, I can think of three ways to do it:
1.
Capture the output before being sent to a controller. I tried to implement this in both my index.php file and my application/configs/routes.php file (by wrapping an isMobile() check around a $routes declaration), but to no avail.
2.
Use a _remap() declaration in each controller.
3.
Load different views for mobile/Wii users.
Now, I can see where it would be more useful to use some techniques over the other. I'd rather lean towards option #1 and option #3. While #3 would reduce the potential code by a third, the first one would allow me to keep things better organized.
My question is, is there a way to use my custom mobile/Wii functions to reroute to different controllers at a basic level? The functions I use are listed below:
Code:
function matchBrowser($needle)
{
$haystack = $_SERVER['HTTP_USER_AGENT'];
return (stripos($haystack, $needle) !== FALSE);
}
function isMobile()
{
$mobiles = array('opera mini',
'opera mobi',
'mobileie',
'iphone',
'ipod');
$isMobile = false;
foreach ($mobiles as $mobile):
if (matchBrowser($mobile)):
$isMobile = true;
break;
endif;
endforeach;
return $isMobile;
}
function isConsole()
{
$consoles = array('wii');
$isConsole = false;
foreach ($consoles as $console):
if (matchBrowser($console)):
$isConsole = true;
break;
endif;
endforeach;
return $isConsole;
}
Any help in this matter would be greatly appreciated. Also, any idea of which way would be better/easier to maintain in the long run would also be very helpful. Thanks in advance!
(If it helps, I'll be testing on a Samsung SCH-i760 phone with Mobile IE and Opera Mobile, as well as my Wii.)