0
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;这句 ,具体作用是什么,我去掉也不影响.有什么特别作用吗??

查看全部 3 个回答

0

个人感觉clone还是要带上