问:如何获取表的所有记录?
状态:我想导出表格的所有记录。现在,我可以导出表格的前10条记录。我该怎么办?
这是我的模特
public function dashboard()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->select = 't.*';
if (Yii::app()->user->checkAccess('Reviewer') || Yii::app()->user->checkAccess('Implementer'))
$criteria->join = "JOIN users u ON (t.creator = u.id)";
if($this->creator):
$criteria->compare('u.username',$this->creator);
else:
if (Yii::app()->user->checkAccess('Creator')):
$criteria->compare('t.creator',Yii::app()->user->id);
endif;
endif;
$criteria->compare('t.request_no',$this->request_no);
$criteria->compare('t.description',$this->description,'true');
if(isset($this->status)):
$criteria->addSearchCondition('t.status',$this->status, false);
endif;
if (Yii::app()->user->checkAccess('Reviewer')):
$criteria->addSearchCondition('t.reviewers',Yii::app()->user->id,true, 'OR');
endif;
if (Yii::app()->user->checkAccess('Implementer')):
$criteria->addSearchCondition('t.implementers',Yii::app()->user->id,true, 'OR');
endif;
//$criteria->order = ' created_date DESC';
$all = new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
$_SESSION['all'] = $all;
$data = new CActiveDataProvider(get_class($this), array(
'pagination'=>array('pageSize'=> Yii::app()->user->getState('pageSize',
Yii::app()->params['defaultPageSize']),),
'criteria'=>$criteria,
));
$_SESSION['limited'] = $data; // get all data and filtered data :)
return $data;
}
感谢您的任何建议
答案 0 :(得分:5)
您必须为数据提供者设置禁用分页。对于该集pagination
属性为false
$all = new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>false,
));
答案 1 :(得分:0)
我找到了解决方案。
$all = new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
get_class($ this)是解决此问题的关键。
答案 2 :(得分:0)
在Yii2中,以下仍然有效。
// query
$queryMessages = Messages::find()->where([
'user_id' => Yii::$app->user->identity->patient->id,
]);
// data provider
$messagesDataProvider = new ActiveDataProvider([
'query' => $queryMessages,
'pagination' => false,
]);