gulltour / mobiledetector
Mobile-Detect库的Yii2扩展
1.0.2
2017-03-17 03:45 UTC
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-29 02:13:50 UTC
README
Mobile-Detect库的Mobile detector Yii2扩展
通过请求信息检测设备类型。
注意
本扩展基于mobiledetect项目 http://mobiledetect.net/。
更多文档和示例请参阅[这里] (http://demo.mobiledetect.net/)。
安装
安装此扩展的首选方式是通过composer。
运行以下命令之一:
php composer.phar require --prefer-dist gulltour/mobiledetector "*"
或
"gulltour/mobiledetector": "*"
将以下内容添加到您的composer.json文件的require部分。
用法
更新配置文件 config/web.php 或 common/main.php
return [ ... 'components' => [ 'mobiledetect' => [ 'class' => 'gulltour\mobiledetect\MobileDetect', ], ], ... ];
在运行应用程序之前设置检测设备类型的处理器
// 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();