neilime/zf2-mobile-detect

Zend Framework 2 module that provides Mobile-Detect features

Installs: 22 961

Dependents: 1

Stars: 27

Watchers: 4

Forks: 3

Open Issues: 2

Language: PHP

1.0 2013-07-01 13:20 UTC

README

Build Status Latest Stable Version Total Downloads Code coverage

NOTE : If you want to contribute don't hesitate, I'll review any PR.

Click here to lend your support to: ZF2 Mobile-Detect and make a donation at pledgie.com !

Introduction

ZF2 Mobile-Detect is a Zend Framework 2 module that provides Mobile-Detect features.

Requirements

Installation

Main Setup

By cloning project
  1. Install Mobile-Detect by cloning it into ./vendor/.
  2. Clone this project into your ./vendor/ directory.
With composer
  1. Add this project in your composer.json:

    "require": {
        "neilime/zf2-mobile-detect": "dev-master"
    }
  2. Now tell composer to download ZF2 Mobile-Detect by running the command:

    $ php composer.phar update
Post installation
  1. Enabling it in your application.config.phpfile.

    <?php
    return array(
        'modules' => array(
            // ...
            'Neilime\MobileDetect',
        ),
        // ...
    );

How to use ZF2 Mobile-Detect

ZF2 Mobile-Detect module provides Mobile_Detect class as a service, helper for views and plugin controllers

  1. Call Mobile-Detect with the service manager

    /* @var $serviceManager \Zend\ServiceManager\ServiceLocatorInterface */ 
    
    $mobileDetect = $serviceManager->get('MobileDetect'); //Retrieve "\Mobile_Detect" object
    $mobileDetect->isMobile();
  2. 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();       
  3. 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();