【发布时间】:2011-12-30 22:49:57
【问题描述】:
我刚刚开始使用 Yii,我只是在创建我的主页,我为这个文件使用了两个视图,index.php 和 column1.php。我的 SiteController.php 中有以下代码
public function actionIndex()
{
// limits query for index page results to 10
$Criteria = new CDbCriteria();
$Criteria->limit = 10;
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->render('index', array(
'ItemDetails' => ItemDetail::model()->findAll($Criteria),
));
}
这只是回忆我想在我的主页上显示的最新 10 条记录。要访问我的 index.php 文件中的记录,我只需使用
<?php foreach($ItemDetails as $ItemDetail):?>
<tr>
<td><?php echo $ItemDetail->title;?></td>
<td><?php echo $ItemDetail->des;?></td>
</tr>
<?php endforeach;?>
唯一的问题是我需要将此代码输出到我的 column1.php 视图。我如何实现这一点?目前我只是得到未定义的变量,或者我应该把所有东西都放在我的 index.php 视图中 - 我有点不确定,所以希望得到一些指导
谢谢
强尼
【问题讨论】:
标签: yii