mrateb
mrateb

Reputation: 2499

Yii2 - Custom Pagination

What is the right way to have variable pagination in Yii2? I mean by this, that I want the user to be able to give the number of items in a page while sending an API request.

I know about setting the pageSize in the dataProvider.

$dataProvider = new SqlDataProvider([
    'sql' => 'SELECT * FROM user WHERE status=:status',
    'params' => [':status' => 1],
    'pagination' => [
        'pageSize' => 20,
    ],
]);

But my question is about anything that is built in that allows the user to send the pageSize through the request? Is there anything built-in to perform this function?

Upvotes: 0

Views: 1084

Answers (1)

gmc
gmc

Reputation: 3990

Leave empty the pagination field in the dataProvider and just add the per-page GET parameter in your calls:

http://your_url/controlller/action?per-page=20

More info here.

Upvotes: 1

Related Questions