Mobile detector
Detect type of device by information from request., (*1)
Notes
This extension based on mobiledetect project http://mobiledetect.net/., (*2)
See [here] (https://github.com/serbanghita/Mobile-Detect/) and [here] (http://demo.mobiledetect.net/) for more documentation and examples., (*3)
Installation
The preferred way to install this extension is through composer., (*4)
Either run, (*5)
php composer.phar require --prefer-dist dkeeper/yii2-mobiledetect "*"
or add, (*6)
"dkeeper/yii2-mobiledetect": "*"
to the require section of your composer.json
file., (*7)
Usage
Update config file config/web.php or common/main.php:, (*8)
return [
...
'components' => [
'mobiledetect' => [
'class' => 'dkeeper\mobiledetect\Detect',
],
],
...
];
Set event handler for detect type of device before run Application, (*9)
// path/to/web/index.php
$application = new yii\web\Application($config);
Yii::$app->on(\yii\base\Application::EVENT_BEFORE_REQUEST,function($event){
Yii::$app->params['detect'] = [
'isMobile' => Yii::$app->mobiledetect->isMobile(),
'isTablet' => Yii::$app->mobiledetect->isTablet(),
];
});
$application->run();