/** * @param array $parameters * @param null $parent * @return string|null */ public function getMobileDeviceType($parameters, $parent = NULL) { /** @var \Detection\MobileDetect $mobileDetection */ $mobileDetection = new \Detection\MobileDetect(); $mobileDetection->setUserAgent($parameters['userAgent']); $type = NULL; if ($mobileDetection->isTablet()) { $type = 'tablet'; } elseif ($mobileDetection->isMobile()) { $type = 'smartPhone'; } else { $parameters['returnResult'] = FALSE; } return $type; }
/** * SetUp method * * @return void */ public function setUp() { parent::setUp(); Request::addDetector('mobile', function ($request) { $detector = new \Detection\MobileDetect(); return $detector->isMobile(); }); Request::addDetector('tablet', function ($request) { $detector = new \Detection\MobileDetect(); return $detector->isTablet(); }); $this->event = new Event('Controller.beforeFilter'); $this->Controller = new MobileComponentTestController(new Request()); //$this->Controller->constructClasses(); $this->Controller->request->session()->delete('User'); Configure::delete('User'); }
/** * The default crypto extension in 3.0 is OpenSSL. * If you are migrating from 2.x uncomment this code to * use a more compatible Mcrypt based implementation */ // Security::engine(new \Cake\Utility\Crypto\Mcrypt()); /** * Setup detectors for mobile and tablet. */ Request::addDetector('mobile', function ($request) { $detector = new \Detection\MobileDetect(); return $detector->isMobile(); }); Request::addDetector('tablet', function ($request) { $detector = new \Detection\MobileDetect(); return $detector->isTablet(); }); /** * Custom Inflector rules, can be set to correctly pluralize or singularize * table, model, controller names or whatever other string is passed to the * inflection functions. * * Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']); * Inflector::rules('irregular', ['red' => 'redlings']); * Inflector::rules('uninflected', ['dontinflectme']); * Inflector::rules('transliteration', ['/å/' => 'aa']); */ /** * Plugins need to be loaded manually, you can either load them one by one or all of them in a single call * Uncomment one of the lines below, as you need. make sure you read the documentation on Plugin to use more * advanced ways of loading plugins
/** * @return boolean whether the user browser is a tablet browser */ public static function isTablet() { $detector = new Detection\MobileDetect(); return $detector->isTablet(); }
/** * Function for detecting tablet client with useragent * * @return bool client is tablet device */ function isTablet() { $md = new \Detection\MobileDetect($this->_request->headers->all(), $this->_request->headers->get('User-Agent')); return $md->isTablet(); }
<?php $detect = new \Detection\MobileDetect(); define('MOBILE', $detect->isMobile()); define('TABLET', $detect->isTablet());