PriymakVl
4/29/2020 - 6:38 PM

yii pagination

yii pagination

<?php
use yii\data\Pagination

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

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


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