[英]different layouts on different views cakephp 2.0
I have this on my controller: 我的控制器上有这个:
class EmployeeAccountsController extends AppController
{
var $layout = 'login';
public function login()
{
}
public function main_board()
{
}
}
what I want to do is that to assign different layouts when I call the view for login() and the view for the main_board. 我想做的是在调用login()的视图和main_board的视图时分配不同的布局。
login() must have layout:login.ctp main_board() must have layout:main_board() login()必须具有layout:login.ctp main_board()必须具有layout:main_board()
is it possible for a single controller to have different layout? 一个控制器可以有不同的布局吗?
Yes it is, and callback beforeFilter into your controller like: 是的,然后将beforeFilter回调到您的控制器中,例如:
class EmployeeAccountsController extends AppController {
protected $layout = 'login';
public function beforeFilter() {
parent::beforeFilter(); //call parent before filter
$this->layout = $this->layout;
}
}
In this case EmployeeAccounts controller will have login layout for all views. 在这种情况下,EmployeeAccounts控制器将具有所有视图的登录布局。
EDIT: just define layout especially for action 编辑:只定义布局,尤其是针对动作
public function action() {
$this->layout = 'layout1';
}
public function action2() {
$this->layout = 'layout2';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.