I'm trying to run a method in a controller that renders the default view on a normal browser, but renders a mobile view when the request is coming from a mobile device.
In app_controller.php
function beforeFilter() {
if ($this->RequestHandler->isMobile()) {
$this->is_mobile = true;
$this->set('is_mobile', true );
$this->autoRender = false;
}
}
and in the controller:
function home(){
...bunch of data grabbing stuff...
if ($this->is_mobile){
$this->autoRender = NULL;
$this->layout = 'empty';
$this->render('/mobile/home');
} else {
$this->layout = 'default';
}
}
When i hit it on a browser (user agent switched to mobile device) it renders the proper mobile/home view file, BUT it ALSO renders the normal, non-mobile view file underneath. Turned on debug, nothing out of the ordinary, except the 2nd, 'normal' view file is being rendered underneath the mysql trace from the mobile view.
Any thoughts on how to fully disable the default view from rendering and just showing the mobile?
CakePHP omits options if they are 'false'; You need to change your code like so:
<?php
$this->autoRender = false;
?>
That should stop the view from rendering;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With