我一直在尝试应用分页,但出现错误。
在控制器中:
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
all() 方法返回的是(对象的)array
而不是object
。而且,正如您在错误中看到的那样,您必须在 object
上使用 __clone method
.
我能问一下你为什么需要这个clone
吗?