Yii Scope 未传递到 CListView 中


Yii Scope not being passed into CListView

我正在尝试将此模型范围传递到我的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;
}