NOTE : If you want to contribute don't hesitate, I'll review any PR.
ZF2 Mobile-Detect is a Zend Framework 2 module that provides Mobile-Detect features.
- Zend Framework 2 (latest master)
- Mobile-Detect (latest master).
- Install Mobile-Detect by cloning it into
./vendor/
. - Clone this project into your
./vendor/
directory.
-
Add this project in your composer.json:
"require": { "neilime/zf2-mobile-detect": "dev-master" }
-
Now tell composer to download ZF2 Mobile-Detect by running the command:
$ php composer.phar update
-
Enabling it in your
application.config.php
file.<?php return array( 'modules' => array( // ... 'Neilime\MobileDetect', ), // ... );
ZF2 Mobile-Detect module provides Mobile_Detect class as a service, helper for views and plugin controllers
-
Call Mobile-Detect with the service manager
/* @var $serviceManager \Zend\ServiceManager\ServiceLocatorInterface */ $mobileDetect = $serviceManager->get('MobileDetect'); //Retrieve "\Mobile_Detect" object $mobileDetect->isMobile();
-
Call Mobile-Detect in a controller
$mobileDetect = $this->mobileDetect(); //Retrieve "\Mobile_Detect" object $mobileDetect->isMobile(); $mobileDetect = $this->mobileDetect( \Zend\Http\Headers::fromString('User-Agent: Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19') ); //Retrieve "\Mobile_Detect" object with arbitrary http headers $mobileDetect->isAndroidOS();
-
Call Mobile-Detect in a view
$mobileDetect = $this->mobileDetect(); //Retrieve "\Mobile_Detect" object $mobileDetect->isMobile(); $mobileDetect = $this->mobileDetect( \Zend\Http\Headers::fromString('User-Agent: Mozilla/5.0 (Linux; Android 4.0.4; Desire HD Build/IMM76D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19') ); //Retrieve "\Mobile_Detect" object with arbitrary http headers $mobileDetect->isAndroidOS();