Controller:
public function actionIndex() { $category = Category::getCategoryimg(); $pages = new Pagination(['totalCount' => $category->count(), 'pageSize' => 1]); $models = $category->offset($pages->offset) ->limit($pages->limit) ->all(); return $this->render('index', [ 'category'=> $category, 'models' => $models, 'pages' => $pages, ]); } Model:
public static function getCategoryimg() { $data = Category::find() ->from('category') ->where(['parent_id' => null]) ->all(); return $data; } Mistake:
Call to a member function count () on array
Question:
Why does count() react to all() ?
Representation:
<?php use yii\widgets\LinkPager; ?> <div class="content-index"> <div class="row"> <?php foreach ($category as $cat): ?> <div class="col-md-3 col-sm-4 col-xs-6"> <div class="thumbnail"> <a href="/category/album?id=<?= $cat->id?>"> <img src="<?= '/backend/web/'.$cat->category_image ?>" alt="image" width="500" height="500" class="img-rounded"> </a> <h4 align="center"><?= $cat->name?></h4> <?php if(!($cat->parent_id == null)) { ?> <h5 align="center">Category: <?= $cat->category->name ?></h5> <? } ?> <a href="/category/view?id=<?= $cat->id?>">Детальніше..</a> </div> </div> <?php endforeach; ?> </div> </div> <?php echo LinkPager::widget([ 'pagination' => $pages, ]);