Yii2 pagination id instead of page

is it possible to use post id in pagination instead of page number example instead of :

&page=2 

it will be

&id=63

Pagination code is :

function actionIndex()
{
    $query = Article::find()->where(['status' => 1]);
    $countQuery = clone $query;
    $pages = new Pagination(['totalCount' => $countQuery->count()]);
    $models = $query->offset($pages->offset)
        ->limit($pages->limit)
        ->all();

    return $this->render('index', [
         'models' => $models,
         'pages' => $pages,
    ]);
}

view :

foreach ($models as $model) {
    // display $model here
}

// display pagination
echo LinkPager::widget([
    'pagination' => $pages,
]);

Not in Yii 2.0. What you’re looking for is called “keyset pagination”. It’s available in Yii3 but not in Yii2.

1 Like

Well, it is definitely possible but not available out of the box. If you want to port it, here’s some references:

1 Like