yii 修改模块使用的布局文件
方法一:
yii模块默认使用系统当前的主题布局文件,如果在主配置文件中配置了主题比如:
访问index.php?r=admin/default/index时,默认使用了protected/views/layout /main.php,如果想使用模块自己的layout文件(protected/modules/admin/views/layout /main.php),需要修改protected/modules/admin/controllers /DefaultController.php,在这个文件内添加下面代码:
public ?$layout = 'application.modules.admin.views.layouts.main';?
方法三:
在模块入口文件 beforeControllerAction中添加处理代码,这个方法发生于动作执行前:(例如AdminModule.php)
??? public function beforeControllerAction($controller, $action)
??? {
??? ?????$controller->layout = 'application.modules.admin.views.layouts.book';
??? ??? if(parent::beforeControllerAction($controller, $action))
??? ??? {
??? ??? ??? // this method is called before any module controller action is performed
??? ??? ??? // you may place customized code here
??? ??? ??? return true;
??? ??? }
??? ??? else
??? ??? ??? return false;
??? }