gpt4 book ai didi

yii - 如何为 Yii 模块中的所有 Controller 设置布局?

转载 作者:行者123 更新时间:2023-12-02 08:39:19 25 4
gpt4 key购买 nike

在我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com