2

Q:如何获取表的所有记录?

状态:我想导出表的所有记录。现在,我可以导出表的前 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;   
    }

感谢您的任何建议

4

3 回答 3

5

您必须为 dataprovider 设置禁用分页。对于那个 setpagination属性为 false

$all = new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
            'pagination'=>false,
        ));
于 2012-11-05T06:35:36.047 回答
0

我找到了解决方案。

$all = new CActiveDataProvider(get_class($this), array(
            'criteria'=>$criteria,
        ));

get_class($this)是解决这个问题的关键。

于 2012-11-05T08:36:10.630 回答
0

在 Yii2 中,以下仍然有效。

    // query
    $queryMessages = Messages::find()->where([
        'user_id' => Yii::$app->user->identity->patient->id,
    ]);

    // data provider
    $messagesDataProvider = new ActiveDataProvider([
        'query' => $queryMessages,
        'pagination' => false,
    ]);
于 2017-04-05T17:13:59.937 回答