D
D
Dmitry2017-11-12 15:06:15
API
Dmitry, 2017-11-12 15:06:15

How to return all elements without pagination in Yii2 RESTful API?

How to return all elements without pagination in Yii2 RESTful API?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-11-12
@timon_it

Then redefine actionIndex() method yourself to do what you need.

public function actionIndex()
    {
        //\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

        $myQuery = mySpecialModel::find();
        $dataProvider = new ActiveDataProvider([
            'query'      => $myQuery,
            'pagination' => [
                'pageSize' => 0,  // ALL results, no pagination
            ],
            'sort'       => [
                'defaultOrder' => [
                    'sortOrder' => SORT_ASC,
                    'manu'      => SORT_ASC,
                ],
            ],
        ]);

        return $dataProvider;
    }

code taken from here: https://github.com/yiisoft/yii2/issues/13544

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question