【发布时间】:2016-02-04 02:46:19
【问题描述】:
我一直在尝试应用分页但出现错误。
在控制器中:
public function actionProperties()
{
$query= Property::find()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count()]);
$propertylist = $query->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('properties',[
'propertylist' => $propertylist,
'pages' => $pages,
]);
}
在视图中:
<?= LinkPager::widget(['pagination' => $pages,]);?>
但出现以下错误。请帮忙...
__clone method called on non-object
【问题讨论】:
-
您确定 $query 从 db 表中返回至少一行吗?
-
为什么不用find()->count()?
标签: php pagination yii2 yii2-advanced-app yii2-basic-app