CakePHP autorender not stopping default view

26,424

Solution 1

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;

Solution 2

if you want to make autorender off for specific view then add

$this->autoRender = false;

in a specific method rather then in app controller

Share:
26,424
tbthorpe
Author by

tbthorpe

Updated on March 06, 2020

Comments

  • tbthorpe
    tbthorpe about 4 years

    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?