CakePHP autorender没有停止默认视图

tbt*_*rpe 3 php cakephp cakephp-1.3

我正在尝试在控制器中运行一个方法,该方法在普通浏览器上呈现默认视图,但在请求来自移动设备时呈现移动视图.

在app_controller.php中

function beforeFilter() { 
    if ($this->RequestHandler->isMobile()) {
        $this->is_mobile = true;
        $this->set('is_mobile', true );
        $this->autoRender = false;
    }
}
Run Code Online (Sandbox Code Playgroud)

并在控制器中:

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';
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在浏览器(用户代理切换到移动设备)上点击它时,它会呈现正确的移动/家庭视图文件,但它也会呈现正常的非移动视图文件.打开调试,没有任何异常,除了第二个"正常"视图文件正在从移动视图的mysql跟踪下面呈现.

有关如何完全禁用渲染默认视图并仅显示移动设备的任何想法?

And*_*ner 18

CakePHP如果它们是'false'则省略选项; 您需要像这样更改代码:

<?php

$this->autoRender = false;

?>
Run Code Online (Sandbox Code Playgroud)

这应该会阻止渲染视图;