如何更改cakephp default.ctp布局目录?

Ali*_*rim 6 cakephp

单独我可以通过使用控制器来更改cakephp默认布局.例如我已经使用过

public function login() {
    $this->layout="make";  //here I have changed layout for single action

        if ($this->request->is('post')) {
            //some code...
        } 
   }
Run Code Online (Sandbox Code Playgroud)

我在这里改变了布局!! 但问题是这个布局不是默认的.我想为所有控制器应用这个布局.我怎么能这样做?

mar*_*ark 13

在你的AppController中

public function beforeRender() {
    parent::beforeRender();

    $this->layout = 'custom';
}
Run Code Online (Sandbox Code Playgroud)


DJ *_*Far 5

从 CakePHP 3.1 开始,视图布局发生了变化:

// In a controller, instead of
$this->layout = 'advanced';

// You should use
$this->viewBuilder()->layout('advanced');
Run Code Online (Sandbox Code Playgroud)