1、Controller中action
<? use yii\data\Pagination; .... public function actionList() { $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, ]); }
默认分页的数量是20,你可以设置pageSize为你想要的
$pages = new Pagination([ 'totalCount' => $totalCount, 'pageSize' => 5, ]);