2016-02-03 28 views
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 
+0

你確定$查詢返回至少一個數據庫表的行嗎? – SohelAhmedM

+0

爲什麼不使用find() - > count()? –

回答

0

all() method返回array(對象)不是object。而且,正如您在錯誤中看到的那樣,您必須在object上使用__clone method

請問爲什麼你需要這個clone