yiiyii-modules

how to use main.php in modules in Yii


I'm creating an admin dashboard in Yii. here is my structure

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

for some reason, my admin panel keeps reading the main.php in the bootstrap folder instead of /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);
    }
}

here is my 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(); ?>

how do i make it ready main.php from /modules/admin/views/layouts/main.php ?


Solution

  • You need to alter the path to the decorative view that your view calls in CController::beginContent():

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

    assuming the path is modules/admin/views/layouts/column2.php