site/index.php 里的变量可以在siteController.php里的actionIndex里赋值
那么layouts/main.php里的呢
因为我做后台 是 上左右结构 我把左边的挖出来了 其他的都没变
site/index.php 里的变量可以在siteController.php里的actionIndex里赋值
那么layouts/main.php里的呢
因为我做后台 是 上左右结构 我把左边的挖出来了 其他的都没变
$this代表的是当前controller的实例
你可以在protected>config>main.php 中设置你的变量。
然后在你的controller的action中,给这些变量赋不同值,这样,就可以实现layout中“左边”div中不同的内容。
参考yii自带的blog demo代码,顺摘抄如下:
(1)protected>config>main.php 中添加如下代码:
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>require(dirname(__FILE__).'/params.php'),
(2)protected>config> 目录下,添加params.php文件,并填写类似代码:
<?php
// this contains the application parameters that can be maintained via GUI
return array(
// this is displayed in the header section
'title'=>'My Yii Blog',
// this is used in error pages
'adminEmail'=>'webmaster@example.com',
// number of posts displayed per page
'postsPerPage'=>10,
// maximum number of comments that can be displayed in recent comments portlet
'recentCommentCount'=>10,
// maximum number of tags that can be displayed in tag cloud portlet
'tagCloudCount'=>20,
// whether post comments need to be approved before published
'commentNeedApproval'=>true,
// the copyright information displayed in the footer section
'copyrightInfo'=>'Copyright © 2009 by My Company.',
);
根据你的实际需求,修改params.php的内容。