作者:用户2ng6zjfjen | 来源:互联网 | 2023-07-06 10:36
1234567891011use yii\data\Pagination;$query = Article::find()->where(['status' => 1]);$countQuery =
1 2 3 4 5 6 7 8 9 10 11
| 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;这句 ,具体作用是什么,我去掉也不影响.有什么特别作用吗??