如何在Yii的模块中使用main.php

时间:2014-02-23 06:36:21

标签: yii yii-modules

我正在Yii中创建一个管理信息中心。这是我的结构

 - Protected
|
 - Modules
|
 -- Views
|
 ---Layouts
|
 --- main.php
 --- column1.php
 --- column2.php
|
 - Themes
|
 -- Bootstrap
|
 --- Views
|
 --- Admin
|
 ---- Layouts
|
 ---- main.php

出于某种原因,我的管理面板一直在读取bootstrap文件夹中的main.php而不是/modules/admin/views/layouts/main.php

/**
 * Base class for all admin controllers.
 */
class AdminController extends CController
{

    /**
     * @var string the default layout for the controller view. Defaults to '/layouts/column1',
     * meaning using a single column layout. See 'protected/modules/admin/views/layouts/column2.php'.
     */
    public $layout = '/layouts/column2';

    /**
     * @var string the pageTitle of the current page.
     */
    public $pageTitle = "";

    /**
     * @var array the breadcrumbs of the current page. The value of this property will
     * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
     * for more details on how to specify this property.
     */
    public $breadcrumbs = array();

    /**
     * @var array admin context menu items. This property will be assigned to {@link TbMenu::items}.
     */
    public $adminMenu = array();

    /**
     * @return array action filters
     */
    public function filters()
    {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules()
    {
        return array(
            array('allow',
                'users' => array('@'),
            //'expression' => 'Yii::app()->user->isAdmin'
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }

    public function beforeRender($view)
    {
        if ($this->adminMenu && !Yii::app()->user->isGuest)
            $this->renderPartial('/layouts/clips/_admin_clip');

        return parent::beforeRender($view);
    }
}

这是我的column2.php

<?php /* @var $this Controller */ ?>
<?php $this->beginContent('/layouts/main'); ?>
<div class="row">
    <div class="span2" id="sidebar">
        <?php
        //a clip is a piece of captured output that can be inserted elsewhere.
        if (isset($this->clips['adminMenuClipID']))
            echo $this->clips['adminMenuClipID'];
        ?>
    </div>
    <div class="span10" id="main-content">
        <?php echo $content; ?>
    </div>
</div>
<?php $this->endContent(); ?>

如何从main.php准备好/modules/admin/views/layouts/main.php

1 个答案:

答案 0 :(得分:0)

您需要更改视图在CController::beginContent()中调用的装饰视图的路径:

$this->beginContent('application.modules.admin.views.layouts.column2')

假设路径为modules/admin/views/layouts/column2.php