xstreamka / yii2-mobile-detect
Mobile_Detect class for Yii2 with the ability to add new devices.
Installs: 10 195
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 2
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-12-13 12:31:38 UTC
README
Mobile_Detect class for Yii2 with the ability to add new devices.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist xstreamka/yii2-mobile-detect "*"
or add
"xstreamka/yii2-mobile-detect": "*"
to the require section of your composer.json
file.
Usage
Once the extension is installed, simply use it in your code by:
xstreamka\mobiledetect\Device::$isPhone;
Add new device (your list of devices)
Configure the component in your configuration file (frontend/config/main.php
):
'components' => [ ... 'device' => [ 'class' => 'xstreamka\mobiledetect\Device', 'tablet' => ['SM-T975'], // Array of users' tablets devices. 'phone' => [] // Array of users' phone devices. ], ... ]
Tools
Device::$isMobile; // Mobile: Tablet or Phone. Device::$isTablet; // Tablet Device::$isPhone; // Phone Device::$isIphone; // iPhone Device::$isSamsung; // Samsung Device::$info; // About device (HTTP_USER_AGENT) // Device::$detect === Mobile_Detect() Device::$detect->isTablet(); Device::$detect->isMobile(); ... Device::$detect->isiOS(); // more here: https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples
Example
<?php use xstreamka\mobiledetect\Device; ... ?> <h1>Hello World</h1> ... <?php if (Device::$isPhone) { ?> <p>text for phone devices</p> <?php } elseif (Device::$isTablet) { ?> <p>text for tablet devices</p> <?php } else { ?> <p>text for other devices</p> <?php } ?> ...