代码如下:查询分组是成功的 但是统计结果都是显示为1,求解。
public function relations() {
return array(
'itemsCount' => array(self::STAT, 'AccessRecord', 'id', 'select' => 'count(id)'),
);
}
public function searchbygroup() {
$criteria = new CDbCriteria;
$criteria->select = '*, count(domain) as itemsCount';
$criteria->with = 'itemsCount'; //调用relations
$criteria->compare('id', $this->id);
...
$criteria->compare('Source', $this->Source, true);
$criteria->group = 'Domain, Province';
$criteria->order = 'itemsCount DESC';
return new CActiveDataProvider($this, array(
'criteria' => $criteria, 'pagination' => array('pageSize' => 20),
));
}
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'alarm-ip-user-url-grid',
'dataProvider' => $model->searchbygroup(),
'filter' => $model,
'columns' => array(
array(
'value' => '$data->itemsCount',
'htmlOptions' => array(
'width' => '20',
'style' => 'text-align:center',
)),
...
),
));