Mobile Browser Detection
#2
Posted 20 August 2010 - 07:43 PM
#3
Posted 22 August 2010 - 03:52 AM
#4
Posted 22 August 2010 - 04:40 AM
Yii::app()->user->isBot Yii::app()->user->botName Yii::app()->user->hasMobileDevice Yii::app()->user->mobileDeviceName
But I like your idea Mike. Obviously you are right that CHttpRequest or a subclass is a better place since CWebUser is a little different (though not really important if implemented as extension). You think this functionality should be in core? I have the feeling an extension is better, because if it's in core we can't guarantee to support all bots/devices for example. At least we would have to monitor these methods from time to time in order to make sure new browsers/bots/devices get added. So I guess it's too much trouble to have it in core.
#5
Posted 22 August 2010 - 06:20 AM

I've also found this:
http://chrisschuld.c...owser-from-php/
But i don't like the classname "Browser" which pollutes the global namespace.
In a perfect world we'd have our own Yii implementation of such a detector (which could even "borrow" some code from the libs above). But that takes some effort and requires a maintainer who keeps things up to date.
An extension should also be fine. Even if i never got the point of wrapping third party classes into an extension instead of using the original class right away.
#7
Posted 13 January 2011 - 11:47 AM
For simplicity's sake i've included some lines to my base controller in components/Controller.php:
private $_isMobile; const RE_MOBILE='/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220)/i'; public function getIsMobile() { if ($this->_isMobile===null) $this->_isMobile=isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE']) || preg_match(self::RE_MOBILE, $_SERVER['HTTP_USER_AGENT']); return $this->_isMobile; }
Now it's easy to use a different layout for mobile devices:
public function init() { if ($this->getIsMobile()) $this->layout='//layouts/mobile' }
Note, that i've blatantly stolen the regular expression from here.
#8
Posted 13 January 2011 - 12:50 PM
#9
Posted 13 January 2011 - 03:17 PM
Thanks for pointing that out, Antonio.
#10
Posted 30 September 2011 - 12:07 AM
Thanks!
#11
Posted 30 September 2011 - 01:20 AM
#12
Posted 30 September 2011 - 08:58 AM
Yii::app()->theme = 'mobile';
That worked for the initial theme change to the mobile version, but I haven't been able to get it to switch back based on a user's input. I'm thinking that the issue is passing parameters to the init() function. Is it even possible to pass parameters to the init() function, or am I going about this the wrong way?
Thanks!
#13
Posted 30 September 2011 - 09:04 AM
HTML5 Boilerplate is ready for it, but it's basically using media queries with a js fallback for older browsers.
There's no need to maintain a separate mobile version IMO.
Unless, of course, you are targeting older mobiles (WAP).
#14
Posted 04 November 2011 - 12:48 PM
-Zeke
#15
Posted 19 November 2011 - 03:45 PM


Quote
#17
Posted 21 November 2011 - 05:39 PM
jacmoe, on 19 November 2011 - 05:31 PM, said:
That how jQuery's new implementation of browser detection works so that way can work too. However it isn't always down to features and support being the reason for detection, a lot of people just want different versions of their sites for mobiles and ipad so a mixture of the both is needed.


Quote
#18
Posted 21 December 2011 - 11:01 AM
jacmoe, on 30 September 2011 - 09:04 AM, said:
HTML5 Boilerplate is ready for it, but it's basically using media queries with a js fallback for older browsers.
There's no need to maintain a separate mobile version IMO.
Unless, of course, you are targeting older mobiles (WAP).
The big issue when using media queries is that your mobile browser will still load a bunch of resources you don't need, then hide them using conditional formatting.
http://www.cloudfour...-is-fools-gold/
NetBeans IDE and Yii projects - Short directions and general tips for managing a Yii application in NetBeans IDE
#19
Posted 21 December 2011 - 11:26 AM
The answer is: no.
And: yes.
No, because if you design for mobile first and use the right tools, lesser browsers will only receive what they make use of.
Yes, because we still haven't figured out exactly how to do this just yet.
There's a lot of research going on, so please don't make the mistake of thinking you can find the answer by performing a simple Google search..
Brad Frost is one you need to study:
http://bradfrostweb.com/blog/
And this web dev advent calendar also has some really great articles on it:
http://24ways.org/2011
#20
Posted 27 December 2011 - 09:46 AM
jacmoe, on 21 December 2011 - 11:26 AM, said:
The answer is: no.
And: yes.
No, because if you design for mobile first and use the right tools, lesser browsers will only receive what they make use of.
Yes, because we still haven't figured out exactly how to do this just yet.
There's a lot of research going on, so please don't make the mistake of thinking you can find the answer by performing a simple Google search..
Brad Frost is one you need to study:
http://bradfrostweb.com/blog/
And this web dev advent calendar also has some really great articles on it:
http://24ways.org/2011
I have been reading into mobile solutions on and off over the past year, but didn't come across anything convincing yet.
Until the pioneers of the web have figured out how to do this right, I'm sticking with maintaining a separate mobile version (using a different layout or theme to offer the same content). I cannot recommend the use of media queries just for the sake of maintainability.
Ofcourse, we all look forward to more optimized solutions

NetBeans IDE and Yii projects - Short directions and general tips for managing a Yii application in NetBeans IDE