Adding PHP Mobile Detect in CakePHP1.3 as a component

cake-logoIt seems that the library is not available for old version of CakePHP specifically in 1.3 only in 2.x. So what I did I converted the library as a component, there’s is nothing special about the conversion actually only if you are new to the Framework. Just download the file and unzip it, put it in your /app/controller/components directory.

Download >> Mobile Detect

How to use it:

In one of your controllers, append it in your $components variable like:

Class MyPageController extends AppController
  public $components = array('MobileDetect'); // adding the libraby in to your components

  public function beforeFilter() {

  public function beforeRender() {
    // check the user's device and render the proper layout
    if($this->MobileDetect->isTablet()) {
      $this->layout = 'tablets';
    } elseif($this->MobileDetect->isMobile()) {
      $this->layout = 'mobiles';
    } else {
      $this->layout = 'default';

To download the original file go here.