0
我一直在嘗試應用分頁,但出現錯誤。
自定義代碼中的YII2分頁錯誤
在控制器:
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,
]);
}
在View:
<?= LinkPager::widget(['pagination' => $pages,]);?>
但是,得到下面的錯誤。請幫助...
__clone method called on non-object
你確定$查詢返回至少一個數據庫表的行嗎? – SohelAhmedM
爲什麼不使用find() - > count()? –