yii2-devicedetect Extension to detect device type on the server side (via user agent)

yii2-device-detect ΒΆ

Yii2 extension for Mobile-Detect library.

To use it just require this library in your composer.json file:

"alexandernst/yii2-device-detect": "0.0.8",

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/ */

Project's GitHub

1 0
3 followers
0 downloads
Yii Version: 2.0
License: GPL-3.0
Category: Others
Developed by: alexandernst
Created on: Apr 2, 2015
Last updated: 9 years ago

Related Extensions