Php Yii:在最近的评论列表中显示已发布的帖子和已批准的评论
我使用了yii框架中的Php Yii:在最近的评论列表中显示已发布的帖子和已批准的评论,php,yii,Php,Yii,我使用了yii框架中的yii博客 我只想在最近的评论列表中显示已发布的帖子和已批准的评论 我在注释模型中使用了这段代码 public function findRecentComments($limit=10) { return $this->with('post')->findAll(array( 'condition'=>'t.status='.self::STATUS_APPROVED.'status='.Post::STATUS_PUBLISHE
yii博客
我只想在最近的评论列表中显示已发布的帖子和已批准的评论
我在注释模型中使用了这段代码
public function findRecentComments($limit=10)
{
return $this->with('post')->findAll(array(
'condition'=>'t.status='.self::STATUS_APPROVED.'status='.Post::STATUS_PUBLISHED,
'order'=>'t.create_time DESC',
'limit'=>$limit,
));
}
但在最近的评论列表中显示所有发布和批准的评论
我想在最近的评论列表中显示已发布的帖子和已批准的评论关系模型的设置条件在with()函数中完成。 我认为findAllByAttributes()更易于阅读,因此下面是使用此函数的解决方案
public function findRecentComments($limit=10)
{
return $this->with(array('post' => array(
'condition' => 'post.status=:status',
'params' => array(':status' => Post::STATUS_PUBLISHED),
)))->findAllByAttributes( array(
self::getTableAlias(false, false).'.status' => self::STATUS_APPROVED
),
array(
'order'=> self::getTableAlias(false, false).'.create_time',
'limit' => $limit
) );
}