yii:如何获取表的所有记录

xcitsw88  于 2022-11-09  发布在  其他
关注(0)|答案(3)|浏览(122)

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

谢谢你的忠告

azpvetkf

azpvetkf1#

必须为数据提供程序设置禁用分页。为此,请将pagination属性设置为false

$all = new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
            'pagination'=>false,
        ));
eulz3vhy

eulz3vhy2#

我找到了解决办法。

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

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

qxsslcnc

qxsslcnc3#

在Yii2中,以下仍然有效。

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

    // data provider
    $messagesDataProvider = new ActiveDataProvider([
        'query' => $queryMessages,
        'pagination' => false,
    ]);

相关问题