作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 Yii 应用程序中,我有一个名为 admin 的模块,因此模块类是 AdminModule,它扩展了 CWebModule 类并位于 AdminModule.php 文件中。根据文档,CWebModule 有一个 layout
属性,它在所有模块 Controller 之间共享,以防 Controller 本身没有定义任何布局。
我的 Controller 没有定义任何布局,我在 AdminModule.php 中放了这个:
$this->layout='webroot.themes.bootstrap.views.layouts.column2';
$this->layoutPath = Yii::getPathOfAlias('webroot.themes.bootstrap.views.layouts');
但是,我在管理模块中的 Controller 仍在使用其他布局,我认为它是在组件目录中的 Controller.php 中定义的布局。这是为什么?如何为特定模块设置共享布局?
最佳答案
解决方案是稍微更改我的代码,如下所示:
$this->layoutPath = Yii::getPathOfAlias('webroot.themes.bootstrap.views.layouts');
$this->layout = 'column2';
与指定路径一样,我不需要为布局指定整个路径别名。我在我的 AdminModule.php 的 init() 函数中有这些行,它工作正常。
关于yii - 如何为 Yii 模块中的所有 Controller 设置布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18015043/
我是一名优秀的程序员,十分优秀!