...\controllers\SiteController.php
public function actionNews()
{
$query = News::find()->count();
$pages = new Pagination([
'totalCount' => $query,
'defaultPageSize' =>10,
]);
$models = News::find()->offset($pages->offset)->limit($pages->limit)->orderBy("date DESC")->all();
return $this->render('news', [
'models' => $models,
'pages' => $pages,
]);
}
..\views\site\news.php
<div class="row">
<div class="col-md-7">
<?php foreach ($models as $model): ?>
<h1 class="page-header"><?= $model->title ?> <small> <?php echo $model['date'] ?></small></h1>
<p><?= $model->article ?></p>
<?php endforeach; ?>
</div>
<div class="col-md-5">
<?PHP
// display pagination
echo LinkPager::widget(['pagination' => $pages,]);
var_dump($pages);
?>
</div>
</div>