Almost all the answers suggest to customize the pagination by creating a new ActiveDataProvider
. By doing so you lost lost the default behaviours of the yii\rest\IndexAction
, such as sorting and filtering.
In fact, yii\rest\IndexAction
is pretty flexible and allows overriding the minimal you need. To customize only the pagination, you can set the pagination property of the IndexAction
without having to create your own ActiveDataProvider
, e.g.:
class CatController extends \yii\rest\ActiveController
{
public static $modelClass = '\app\models\Cat';
public function actions()
{
return array_merge_recursive(parent::actions(), [
'index' => [
'pagination' => [
'defaultPageSize' => 50,
'pageSizeLimit' => [1, 50],
],
],
]);
}
}
The trick above is the use of array_merge_recursive()
such that the custom params are merged with the default ones, leaving the other default behaviours to work.
The entire list of pagination parameters can be found in the API doc. It is up to you to decide the combination that fits the application most, e.g.:
- set a larger
defaultPageSize
- set
pageSizeLimit
to allow pageSize
of 0, i.e. all items
- disable pagination at all by setting it to
false