CActiveDataProvider
生成自动查询以计算项目总数:
SELECT COUNT(DISTINCT `t`.`id`) FROM `transaction` `t` LEFT OUTER JOIN `partner` `partner` ON (`t`.`partner_id`=`partner`.`id`)
这个查询很慢,因为包含连接,如何设置manualy总计数,并禁用此自动查询?
答案 0 :(得分:1)
尝试使用CActiveDataProvider-> countCriteria。 http://www.yiiframework.com/doc/api/1.1/CActiveDataProvider#countCriteria-detail
答案 1 :(得分:1)
您可以手动为CActiveDataProvider设置total item count以防止自动计算。
class Model extends CActiveRecord {
public function search(){
$criteria = new CDbCriteria;
// your criteria here
$data_provider = new CActiveDataProvider($this, array('criteria'=>$criteria));
// replace $this->count( $criteria ) with your own condition or another criteria
$data_provider->setTotalItemCount( $this->count( $criteria ) );
return $data_provider;
}
}