如何在Yii中的模块中使用main.php
我正在用Yii创建一个管理仪表板。这是我的结构如何在Yii中的模块中使用main.php,yii,yii-modules,Yii,Yii Modules,我正在用Yii创建一个管理仪表板。这是我的结构 - Protected | - Modules | -- Views | ---Layouts | --- main.php --- column1.php --- column2.php | - Themes | -- Bootstrap | --- Views | --- Admin | ---- Layouts | ---- main.php 出于某种原因,我的管理面板一直在读取引导文件夹中的main.php,而不
- Protected
|
- Modules
|
-- Views
|
---Layouts
|
--- main.php
--- column1.php
--- column2.php
|
- Themes
|
-- Bootstrap
|
--- Views
|
--- Admin
|
---- Layouts
|
---- main.php
出于某种原因,我的管理面板一直在读取引导文件夹中的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(); ?>
如何从
/modules/admin/views/layouts/main.php
中准备好main.php
?您需要更改视图调用的装饰视图的路径:
假设路径是
modules/admin/views/layouts/column2.php
,您可以编写'application.modules.layout.main.php',在其中设置布局public$layout='application.modules.layout.main.php'代码>不工作。现在column2.php不包括在内。看,您可以使用相同的语句。实际上,应用程序指的是受保护的文件夹。当使用从另一个文件夹访问文件夹时,您必须使用应用程序。你可以使用“application.modules.layouts.column2.php”nope。也不要工作。它正确读取column1.php和column2.php。只是使用了错误的main.phpnope。也不要工作。使用这个,public$layout='/layouts/column2'
它正确读取column1.php
和column2.php
。只是在生成页面时使用了错误的main.php
。在my column2.php中更改吗?这是什么变化<代码>$this->beginContent('/layouts/main')代码>是。在column1.php
或任何其他您想要使用不同装饰视图的布局中(在您的例子中是main.php
),hmmm它仍然不包括主视图<代码>
*包括正确的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);
}
}