【问题标题】:Different interface layout for different level users in yiiyii中不同级别用户的不同界面布局
【发布时间】:2015-08-04 01:21:42
【问题描述】:

我是 Yii 的新手。我正在用 PHP 开发一个带有 YII 框架的系统。如何为不同的模块设置不同的布局?我希望模块 A 具有接口 A,模块 B 具有接口 B。但我所知道的是,所有模块登录的接口登录都是相同的。谁能给我一盏灯?

更新:

我找到了一种方法,即包括:

$this->layout = $layout;

在渲染页面之前在控制器内部的动作函数上。但是,我发现它的效率不如我需要重复该行的每个动作。有没有办法可以在 config/main.php 页面上进行设置?大概在这部分:

'modules'=>array(
     'gii'=>array(
        'class'=>'system.gii.GiiModule',
        'password'=>'123',
        'generatorPaths' => array('bootstrap.gii'),
     ),          

     'admin',
     'consultant',
     'client',
),

【问题讨论】:

标签: php user-interface layout yii module


【解决方案1】:

您可以像这样在config 中为您的模块设置变量:

'modules'=>array(
     'gii'=>array(
        'class'=>'system.gii.GiiModule',
        'password'=>'123',
        'generatorPaths' => array('bootstrap.gii'),
     ),          

     'admin' => array(
        'layout' => 'your_layout' //The layout for this module
     ),
     'consultant',
     'client',
),

通过这种方式,您可以为每个模块实现默认布局。无需添加controller 方法或变量。

有关更多信息,请参阅文档:herehere

【讨论】:

  • 嗨,我尝试了你提到的方式,但是我应该如何编写代码才能连接到我拥有的控制器?前任。该模块是管理员。在 admin->components->Controller.php 里面
  • 来自我的第一个“这里”链接:“$layout。此模块内的控制器共享的布局。如果控制器明确声明了自己的布局,则此属性将被忽略。如果这个为 null(默认),将使用应用程序的布局或父模块的布局(如果可用)。如果为 false,则不会使用任何布局。这是您在config 中设置的布局变量。所以尝试将它设置为false,如果它显示没有布局它可以工作并且Yii 可能找不到您的特定布局。
【解决方案2】:

试试这个:

class YourController extends Controller {

    public $layout = 'your_layout';

}

【讨论】:

    猜你喜欢
    • 2013-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-03
    • 1970-01-01
    • 2015-07-09
    • 2015-12-13
    相关资源
    最近更新 更多