yii2-device-detect

by alexandernst

alexandernst / yii2-device-detect

Yii2 extension for Mobile-Detect library

129 Stars 39 Forks Last release: over 5 years ago (0.0.9) Other 36 Commits 12 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

yii2-device-detect

Yii2 extension for Mobile-Detect library.

To use it just require this extension in your

composer.json
file:
"alexandernst/yii2-device-detect": "0.0.12",

And then add it to your components configuration in Yii2:

'bootstrap' => ['devicedetect'],
'components' => [
    'devicedetect' => [
        'class' => 'alexandernst\devicedetect\DeviceDetect'
    ],
]

Some basic detections are available in Yii's

params
:
var_dump(Yii::$app->params['devicedetect']);

array (size=3) 'isMobile' => boolean false 'isTablet' => boolean false 'isDesktop' => boolean true

You can also use it from anywhere in your code, calling Mobile-Detect's API:

/*Detect a mobile device*/
\Yii::$app->devicedetect->isMobile();

/Detect a tablet device/ \Yii::$app->devicedetect->isTablet();

/*Check all available methods here: http://demo.mobiledetect.net/ */

Or using the an alias:

\Yii::getAlias('@device'); //return 'mobile', 'tablet' or 'desktop'.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.