您好我是Yii的新手,我想要做的是我有酒店及其物品,我想要显示最高评价。所以在siteController
我得到的数据非常好。但是我尝试获取多个数据提供者并渲染index
页面,但它无法识别已更改的数据提供者名称。
for ex
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$dataProviderHotel=new CActiveDataProvider('Hotel',array(
'criteria'=>array(
'condition'=>'hotel_rating > 8',
),
'pagination'=>array(
'pageSize'=>20,
),
));
$dataProviderItems = new CActiveDataProvider('Item',array(
'criteria'=>array(
'condition'=>'hotel_rating > 8',
),
'pagination'=>array(
'pageSize'=>20,
),
));
$this->render('index',array(
'dataProvider'=>array($dataProviderHotel,$dataProviderItem),
));
}
并且在视图中抛出异常,即dataProviderHotel未定义 查看代码是
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProviderHotel,
'summaryText'=>'',
'itemView'=>'_topHotels',
)); ?>
答案 0 :(得分:4)
应该如下:
$this->render('index',array(
'dataProvider1'=>$dataProviderHotel,
'dataProvider2'=>$dataProviderItem
));
然后在你看来:
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider1,
'summaryText'=>'',
'itemView'=>'_topHotels',
));
?>