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 method used from http://detectmobilebrowsers.com/
Tested on Yii 1.1.8 - 1.1.10, should work on all versions.
Install as an application component, in your config:
'components' => array( 'detectMobileBrowser' => array( 'class' => 'wabbit.extensions.yii-detectmobilebrowser.XDetectMobileBrowser', ), ),
You can use it like this:
if (Yii::app()->detectMobileBrowser->showMobile) { // do something, like using a different layout/theme }
You can explicitly override the value, for example like this:
public function actionShowMobile() { Yii::app()->detectMobileBrowser->showMobile = true; $this->redirect(array('/site/index')); }
Total 2 comments
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.