Hello All,
In this blog we will discuss about how to make your website working with proper layout in the mobile devices.
For this we can use CakePHP's RequestHandler's isMobile function to check if a mobile device is accessing the site.
We can make this liable by putting following code in the AppController by using cakephp beforeRender function.
public $components = array('RequestHandler');
public function beforeRender() {
parent::beforeRender();
if ($this->RequestHandler->isMobile()) {
$this->layout = 'mobile';
}else{
$this->layout = 'WebsiteLayout';
}
The above code will check if the request has come in from mobile device or not.
Lastly, by setting this criteria It sets a property and view variable to allow actions and views to adjust based on the mobile layout we define by checking if the mobile device is accessing it.
0 Comment(s)