我正在尝试将此模型范围传递到我的CListView中
这是我的评论模型中的范围
public function scopes()
{
return array(
'lastestComment'=>array(
'alias' => 't',
'select'=>array('t.*,t2.*'),
'join'=>'JOIN `comments_posts` AS t2',
'condition'=>'t.id=t2.commentId',
'order'=>'t.createDate ASC',
'limit'=>'5'
)
);
}
在我看来,我有这个
$dataProvider=new CActiveDataProvider(Comment::model()->lastestComment());
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view', //view file location
));
在视图中,我调用$data
我只能获取comments
模型中的值,而不能从范围联接中的comments_post
表中获取值。有什么想法吗?
你不必为了达到你想要的东西而变得如此复杂,
YII永远很简单
在model
public function relations() {
return array(
'posts' => array(self::HAS_MANY, "CommentPosts", array("commentId" => "id")),
);
}
在view
中,您可以获取comment table
中的数据
$data->column_name
和comment_post table
中的数据为
foreach($data->posts as $postings){
$postings->column_name;
}