detectmobilebrowser

handles detecting mobile browsers
18 followers

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/

Requirements

Tested on Yii 1.1.8 - 1.1.10, should work on all versions.

Usage

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'));
}

Resources

Total 2 comments

#6961 report it
marcovtwout at 2012/02/16 03:03am
Re: E.g. for browser switch in SiteController

I would set it in Controller->beforeRender(). If you need to set it sooner, I recommend beforeAction().

#6684 report it
philippfrenzel at 2012/01/28 09:07am
E.g. for browser switch in SiteController

Hope this helps someone... took me a view hours to find out;)

class SiteController extends Controller    
{
 
        //to change the main layout, depending on a mobile or none mobile device
        public function init(){
            if (Yii::app()->detectMobileBrowser->showMobile) {
                $this->layout='//layouts/mobile';
            }            
        }
}

Leave a comment

Please to leave your comment.

Create extension