Set default layout for entire application. i.e, created layout file in /src/Template/Layout/admin.ctp
class AppsController extends Controller {
public function beforeFilter(Event $event) {
parent::beforeFilter($event);
$this->viewBuilder()->layout('admin'); // For Version >= 3.1 or
$this->layout = 'admin'; // for version < 3.1
// your other code should be here
}
}
Set default layout for specific action in application. i.e, application have different layout in login page in /src/Template/Layout/login.ctp
class UsersController extends Controller {
public function login() {
$this->viewBuilder()->layout('login'); // For Version >= 3.1 or
$this->layout = 'login'; // for version < 3.1
//your other code should be here
}
}
Change Layout for specific Controller. for i.e, you need different layout for all method of specific controller
class UsersController extends Controller {
public function beforeFilter(Event $event) {
parent::beforeFilter($event);
$this->viewBuilder()->layout('user_layout'); // For Version >= 3.1 or
$this->layout = 'user_layout'; // for version < 3.1
//your other code should be here
}
}