src/Controller/Component/MobileComponent.php
public function setMobile() {
		if ($this->isMobile === null) {
			$this->isMobile();
		}
		$forceMobile = $this->Controller->getRequest()->getSession()->read('User.mobile');

		if ($forceMobile !== null && !$forceMobile) {
			$this->setMobile = false;
		} elseif ($forceMobile !== null && $forceMobile || $this->isMobile()) {
			$this->setMobile = true;
		} else {
			$this->setMobile = false;
		}

		//$urlParams = Router::getParams(true);
		$urlParams = [];
		if (!isset($urlParams['pass'])) {
			$urlParams['pass'] = [];
		}
		$urlParams = array_merge($urlParams, $urlParams['pass']);
		unset($urlParams['pass']);
		if (isset($urlParams['prefix'])) {
			unset($urlParams['prefix']);
		}

		if ($this->setMobile) {
			$urlParams['?']['mobile'] = 0;
			$url = Router::url($urlParams);
			$this->Controller->set('desktopUrl', $url);
		} else {
			$urlParams['?']['mobile'] = 1;
			$url = Router::url($urlParams);
			$this->Controller->set('mobileUrl', $url);
		}

		Configure::write('User.setMobile', (int)$this->setMobile);

		if (!$this->setMobile) {
			return;
		}

		$this->Controller->viewBuilder()->setClassName('Theme');
		$this->Controller->viewBuilder()->setTheme('Mobile');
	}
public function setMobile() {
		if ($this->isMobile === null) {
			$this->isMobile();
		}
		$forceMobile = $this->Controller->getRequest()->getSession()->read('User.mobile');

		if ($forceMobile !== null && !$forceMobile) {
			$this->setMobile = false;
		} elseif ($forceMobile !== null && $forceMobile || $this->isMobile()) {
			$this->setMobile = true;
		} else {
			$this->setMobile = false;
		}

		//$urlParams = Router::getParams(true);
		$urlParams = [];
		if (!isset($urlParams['pass'])) {
			$urlParams['pass'] = [];
		}
		$urlParams = array_merge($urlParams, $urlParams['pass']);
		unset($urlParams['pass']);
		if (isset($urlParams['prefix'])) {
			unset($urlParams['prefix']);
		}

		if ($this->setMobile) {
			$urlParams['?']['mobile'] = 0;
			$url = Router::url($urlParams);
			$this->Controller->set('desktopUrl', $url);
		} else {
			$urlParams['?']['mobile'] = 1;
			$url = Router::url($urlParams);
			$this->Controller->set('mobileUrl', $url);
		}

		Configure::write('User.setMobile', (int)$this->setMobile);

		if (!$this->setMobile) {
			return;
		}

		$this->Controller->viewBuilder()->setClassName('Theme');
		$this->Controller->viewBuilder()->setTheme('Mobile');
	}
public function setMobile ( ) { if ( $ this -> isMobile === null ) { $ this -> isMobile ( ) ; } $ forceMobile = $ this -> Controller -> getRequest ( ) -> getSession ( ) -> read ( 'User.mobile' ) ; if ( $ forceMobile !== null && ! $ forceMobile ) { $ this -> setMobile = false ; } elseif ( $ forceMobile !== null && $ forceMobile || $ this -> isMobile ( ) ) { $ this -> setMobile = true ; } else { $ this -> setMobile = false ; } //$urlParams = Router::getParams(true); $ urlParams = [ ] ; if ( ! isset ( $ urlParams [ 'pass' ] ) ) { $ urlParams [ 'pass' ] = [ ] ; } $ urlParams = array_merge ( $ urlParams , $ urlParams [ 'pass' ] ) ; unset ( $ urlParams [ 'pass' ] ) ; if ( isset ( $ urlParams [ 'prefix' ] ) ) { unset ( $ urlParams [ 'prefix' ] ) ; } if ( $ this -> setMobile ) { $ urlParams [ '?' ] [ 'mobile' ] = 0 ; $ url = Router :: url ( $ urlParams ) ; $ this -> Controller -> set ( 'desktopUrl' , $ url ) ; } else { $ urlParams [ '?' ] [ 'mobile' ] = 1 ; $ url = Router :: url ( $ urlParams ) ; $ this -> Controller -> set ( 'mobileUrl' , $ url ) ; } Configure :: write ( 'User.setMobile' , ( int ) $ this -> setMobile ) ; if ( ! $ this -> setMobile ) { return ; } $ this -> Controller -> viewBuilder ( ) -> setClassName ( 'Theme' ) ; $ this -> Controller -> viewBuilder ( ) -> setTheme ( 'Mobile' ) ; }
Sets mobile views as `Mobile` theme.

Only needs to be called if auto is set to false.
Then you probably want to call this from your AppController::beforeRender().

@return void
Sets mobile views as Mobile theme .