Reputation: 4469
Individually I am able to change cakephp default layout by using controller.For example I have used
public function login() {
$this->layout="make"; //here I have changed layout for single action
if ($this->request->is('post')) {
//some code...
}
}
Here I have changed layout!! But the problem is this layout is not default.I want to apply this layout for all controller.How can I do this?
Upvotes: 6
Views: 18381
Reputation: 2016
In CakePHP 3.6.2 you can not use $this->layout
because is deprecated. try following code.
$this->viewBuilder()->setLayout('LAYOUT_NAME');
Upvotes: 1
Reputation: 506
As of CakePHP 3.1, view layouts have changed:
// In a controller, instead of
$this->layout = 'advanced';
// You should use
$this->viewBuilder()->layout('advanced');
Upvotes: 5
Reputation: 21
This answer may no longer apply in CakePHP 3.0.5. It requires an event object as an argument in the beforeRender() function.
Try changing the $layout property in the controller itself.
public $layout = 'non-default'
will change the layout used by all views defined by the controller to src/Template/Layout/non-default.ctp
Upvotes: 2
Reputation: 21743
In your AppController
public function beforeRender() {
parent::beforeRender();
$this->layout = 'custom';
}
Upvotes: 13