israelfl/yii2-ifl-device-detect

Yii2 extension for Mobile-Detect library

0.0.3 2017-06-15 07:34 UTC

This package is auto-updated.

Last update: 2024-03-12 20:37:30 UTC


README

Yii2 extension for Mobile-Detect library.

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

"israelfl/yii2-ifl-device-detect": "0.0.1",

And then add it to your components configuration in Yii2:

'bootstrap' => ['devicedetect'],
'components' => [
	'devicedetect' => [
		'class' => 'israelfl\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
  'os' => string 'android'|'ios'|'wphone'
  'isiOS' => boolean false
  'isAndroid' => boolean true
  'isWindowsPhone' => boolean false

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'.