Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexandernst/yii2-device-detect
Yii2 extension for Mobile-Detect library
https://github.com/alexandernst/yii2-device-detect
Last synced: about 3 hours ago
JSON representation
Yii2 extension for Mobile-Detect library
- Host: GitHub
- URL: https://github.com/alexandernst/yii2-device-detect
- Owner: alexandernst
- License: other
- Created: 2015-03-25T21:36:14.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-09-02T11:34:28.000Z (over 4 years ago)
- Last Synced: 2025-01-04T20:12:01.214Z (7 days ago)
- Language: PHP
- Size: 28.3 KB
- Stars: 136
- Watchers: 11
- Forks: 37
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-yii2 - alexandernst/yii2-device-detect
README
# yii2-device-detect
Yii2 extension for [Mobile-Detect](https://github.com/serbanghita/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:
~~~php
'bootstrap' => ['devicedetect'],
'components' => [
'devicedetect' => [
'class' => 'alexandernst\devicedetect\DeviceDetect'
],
]
~~~Some basic detections are available in Yii's `params`:
~~~php
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:
~~~php
/*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:
~~~php
\Yii::getAlias('@device'); //return 'mobile', 'tablet' or 'desktop'.
~~~