Php 自定义代码中的YII2分页错误
我一直在尝试应用分页,但出现错误。Php 自定义代码中的YII2分页错误,php,pagination,yii2,yii2-advanced-app,yii2-basic-app,Php,Pagination,Yii2,Yii2 Advanced App,Yii2 Basic App,我一直在尝试应用分页,但出现错误。 在控制器中: 鉴于: 返回一个数组(对象)而不是对象。并且,正如您从错误中看到的,您必须对对象使用克隆方法 我可以问一下为什么需要这个克隆吗?您确定$query至少从db表返回一行吗?为什么不使用find()->count()? public function actionProperties() { $query= Property::find()->all(); $countQuery = clone $que
在控制器中: 鉴于: 返回一个
数组
(对象)而不是对象
。并且,正如您从错误中看到的,您必须对对象
使用克隆方法
我可以问一下为什么需要这个克隆吗?您确定$query至少从db表返回一行吗?为什么不使用find()->count()?
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