use yii\data\Pagination;
$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,
]);
做分页的时候代码都要加$countQuery = clone $query;这句 ,具体作用是什么,我去掉也不影响.有什么特别作用吗??
MYYA
慕容3067478
牧羊人nacy