githubjeka / yii2-rest

Yii2 REST API template
Other
159 stars 76 forks source link

How i can change limit in output? #15

Open dsidorenko opened 8 years ago

dsidorenko commented 8 years ago

Hello! Default limit 20, I set limit ?page=1&per-page=50 but 50 is max value where i can disable pagination?

githubjeka commented 8 years ago

http://stackoverflow.com/questions/27421798/yii2-how-do-change-pagination-per-page-into-restful-web-service-api

dsidorenko commented 8 years ago

I saw it, but did not understand where I have to write these lines?)

<?php
namespace rest\versions\v1\controllers;

use yii\data\ActiveDataProvider;
use yii\filters\auth\QueryParamAuth;
use yii\rest\ActiveController;

class ModelsController extends ActiveController
{

    public $modelClass = 'common\models\Models';

    public function behaviors()
    {
        $behaviors = parent::behaviors();
//        $behaviors['authenticator'] = [
//            'class' => QueryParamAuth::className(),
//        ];
        return $behaviors;
    }
    public function actionIndex()
    {
        return new ActiveDataProvider([
            'pageSizeLimit' => [0, 50],
        ]);
    }
}

does not work

dsidorenko commented 8 years ago

I saw it, but did not understand where I have to write these lines?)

<?php
namespace rest\versions\v1\controllers;

use yii\data\ActiveDataProvider;
use yii\filters\auth\QueryParamAuth;
use yii\rest\ActiveController;

class ModelsController extends ActiveController
{

    public $modelClass = 'common\models\Models';

    public function behaviors()
    {
        $behaviors = parent::behaviors();
        return $behaviors;
    }
    public function actionIndex()
    {
        return new ActiveDataProvider([
            'pageSizeLimit' => [0, 50],
        ]);
    }
}

does not work

githubjeka commented 8 years ago

See API ActiveDataProvider and his pagination. After see property of Pagination.

 public function actionIndex()
    {
        return new ActiveDataProvider([
            'pagination' => [
                 'defaultPageSize' => 20 // to set default count items on one page
                 'pageSize' => 25 //to set count items on one page, if not set will be set from defaultPageSize
                 'pageSizeLimit' => [1, 50], //to set range for pageSize 
             ],
        ]);
    }

To disable pagination:

 public function actionIndex()
    {
        return new ActiveDataProvider([
            'pagination' => false,
        ]);
    }