Yii2 Pagination

Please help, i’m beginner. I have an error “__clone method called on non-object”

I have KomentarController.php




public function actionTampil()

	{

	    $query = Komentar::find()->all();

	    $countQuery = clone $query;

	    $pages = new Pagination(['totalCount' => $countModels->count()]);

	    $models = $query->offset($pages->offset)

	        ->limit($pages->limit)

	        ->all();


	    return $this->render('tampil', [

	         'models' => $models,

	         'pages' => $pages,

	    ]);

}



and view on tampil.php




use yii\helpers\Html;

use yii\widgets\LinkPager;


foreach ($models as $key => $model) {


echo LinkPager::widget([

    'pagination' => $pages,

]);

}



Why




$countQuery = clone $query;



?

I think using clone for copy dump value. what should I do?




$query = Komentar::find()->all();



returns all records.

So $pages is:




$pages = new Pagination(['totalCount' => count($query)]);



I change code to




	public function actionTampil()

	{

        $query = Komentar::find()->all();


        $pagination = new Pagination([

            'PageSize' => 3,

            'totalCount' => count($query)]);


        $comments = $query->offset($pagination->offset)

            ->limit($pagination->limit)

            ->all();


        return $this->render('tampil', [

            'comments' => $comments,

            'pagination' => $pagination,

        ]);

    

	}



and found error "Call to a member function offset() on array"