Yii cgridview getValidators中的计数和排序错误
我在添加STAT时遇到一个错误。我试图计算每个用户的响应数量,并根据desc order对其进行排序。 我的错误:CActiveDataProvider及其行为没有名为getValidators的方法或闭包 关系: 'stickerCount'=>arrayself::STAT'UserSticker'、'user_id', 控制器:Yii cgridview getValidators中的计数和排序错误,yii,Yii,我在添加STAT时遇到一个错误。我试图计算每个用户的响应数量,并根据desc order对其进行排序。 我的错误:CActiveDataProvider及其行为没有名为getValidators的方法或闭包 关系: 'stickerCount'=>arrayself::STAT'UserSticker'、'user_id', 控制器: $likes=new CActiveDataProvider('UserSticker'); $this->render('index',array(
$likes=new CActiveDataProvider('UserSticker');
$this->render('index',array(
'likes'=>$likes,
'sort'=>array(
'defaultOrder'=>'stickerCount DESC',
),
));
<?php
$this->widget ( 'bootstrap.widgets.TbGridView', array (
'id'=>'follower',
'type'=>'striped condensed',
'dataProvider'=>$likes,
'filter'=>$likes,
'columns'=> array(
'stickerCount',
)));
?>
试试这个:
$criteria = new CDbCriteria();
$criteria->join = 'JOIN (SELECT user_id, count(*) As stickerCounter '
. 'FROM user_sticker GROUP BY user_id) userSticker '
. 'ON userSticker.user_id = t.id';
$likes = new CActiveDataProvider('MainTable',array(
'criteria'=>$criteria,
));
...
不能在排序中使用统计关系字段。为此,您需要在条件中添加一个子查询。好的,但我仍然得到错误CActiveDataProvider,它的行为没有名为getValidators的方法或闭包。在我的gridview中,我是否只需要获取标签计数器?您可以发布您的视图文件吗?