我正在尝试列出CGridView
指定用户的帖子,但出现错误。这样做的正确方法是什么?
控制器.php
public function actionListPosts($id)
{
$criteria = new CDbCriteria;
$criteria->with=array('posts');
$criteria->condition='t.id=:user_id';
$criteria->params=array(':user_id'=>$id);
$dataProvider=new CActiveDataProvider('Users', array(
'criteria' => $criteria
));
$this->render('list',array(
'dataProvider'=>$dataProvider,
));
}
查看.php:
<?php $this->widget('zii.widgets.grid.CGridView',array(
'id'=>'events-grid',
'dataProvider'=>$dataProvider->posts,
'columns'=>array(
'id',
'name',
),
)); ?>
错误:
Property "CActiveDataProvider.posts" is not defined.