2

Q: How to get all records of table?

Status : I would like to export all records of the table. Now, I can export the first 10 records of the table. How can I do?

This is my model

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;   
    }

Thank for your any advice

3 Answers 3

5

You must set the disable pagination for the dataprovider . For that set pagination attibute to false

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

I found the solution.

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

get_class($this) is the key to solve this problem.

0

In Yii2 the following still works.

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

    // data provider
    $messagesDataProvider = new ActiveDataProvider([
        'query' => $queryMessages,
        'pagination' => false,
    ]);
1
  • Your answer is retrieving the data by user_id. It is not right one what I needed. I already found the solution since 2012. please check my answer.
    – Thu Ra
    Apr 6, 2017 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.