Handles detecting mobile browsers. Results are stored locally for caching calls within the same request, and stored in a cookie for caching across requests. Detection regex used from http://detectmobilebrowsers.com/
Tested on Yii 1.1.8 - 1.1.12, should work on all versions.
Install as an application component, in your config:
'components' => array( 'detectMobileBrowser' => array( 'class' => 'ext.yii-detectmobilebrowser.XDetectMobileBrowser', ), ),
You can get the current user preference like this:
if (Yii::app()->detectMobileBrowser->showMobile) { // do something, like using a different layout/theme }
By default it will use the automatically detected value. You can also set the preference yourself like this:
public function actionShowMobile() { Yii::app()->detectMobileBrowser->showMobile = true; $this->redirect(array('/site/index')); }
Total 10 comments
This problem does not seem related to this extension. Please create a topic in the forums if you seek help.
hi, im facing an issue when im taking my app in mobile device ie losing session.i have a login feature in app that works fine but after login all of my session values are disappeared.no idea why.
wow that was quick, awesome work with the extension.
Really helpful and so simple to use.
I've used part of your changes in the new 1.1 release, thanks again!
What's new:
Thanks for your feedback, I will review your code additions and consider adding them to the source code.
It's being maintained on Google Code: https://code.google.com/p/yii-detectmobilebrowser/
I found that the setCookie function wasn't working for me when I had my page in the base public_html directory.
I had to change the following line in setCookie function from: $cookie->path = Yii::app()->baseUrl; to: $cookie->path = Yii::app()->baseUrl . '/';
In addition to this, I have also made some minor changes: 1) Added support to know the actual device type and desired device type (i.e. if you allow toggling of device type) 2) Added latest detection code 3) Added a reset function for resetting of the getShowMobile function
You can use the latest regex by downloading it from here: http://detectmobilebrowsers.com/
I'm still fairly new to Yii, so I'm not sure if I did something wrong, but when I put this under: protected/extensions/yii-detectmobilebrowser it didn't work with the suggested main.php config changes
I looked up in http://www.yiiframework.com/doc/guide/1.1/en/extension.use and put the following in the main.php config to get it to work:
instead of the suggestion:
just thought I would mention it incase others are having similar issues.
If someone knows of something I did wrong, then please let me know.
Cheers
I would set it in Controller->beforeRender(). If you need to set it sooner, I recommend beforeAction().
Hope this helps someone... took me a view hours to find out;)
Leave a comment
Please login to leave your comment.