Php yii:如何获取表格的所有记录
Q:如何获取表的所有记录 状态:我想导出表的所有记录。现在,我可以导出表的前10条记录。我该怎么办 这是我的模型Php yii:如何获取表格的所有记录,php,yii,Php,Yii,Q:如何获取表的所有记录 状态:我想导出表的所有记录。现在,我可以导出表的前10条记录。我该怎么办 这是我的模型 public function dashboard() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria=new CDbCriteria; $
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;
}
感谢您的建议您必须为数据提供程序设置禁用分页。对于该设置,
分页
attibute为false
$all = new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>false,
));
我找到了解决办法
$all = new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
获取类($this)是解决此问题的关键。在Yii2中,以下方法仍然有效
// query
$queryMessages = Messages::find()->where([
'user_id' => Yii::$app->user->identity->patient->id,
]);
// data provider
$messagesDataProvider = new ActiveDataProvider([
'query' => $queryMessages,
'pagination' => false,
]);
谢谢,这是我的话。!您的答案是按用户id检索数据。这不是我所需要的。自2012年以来,我已经找到了解决方案。请核对我的答案。