Alimon Karim
Alimon Karim

Reputation: 4469

How to change cakephp default.ctp layout directory?

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

Answers (4)

Bhavik Hirani
Bhavik Hirani

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

DJ Far
DJ Far

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

Roberto
Roberto

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

mark
mark

Reputation: 21743

In your AppController

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

    $this->layout = 'custom';
}

Upvotes: 13

Related Questions