public function init() { parent::init(); if ($this->page == 'index') { if ($this->cat == 'all' or $this->cat == null) { $query = Logotypes::find()->limit(15); } else { $query_cat = new Query(); $query_cat->select('id')->from('category')->where(['name' => $this->cat]); $cat_id = $query_cat->all()[0]['id']; $query = Logotypes::find()->limit(15)->where(['category' => $cat_id]); } $logos = $query->all(); shuffle($logos); } else { if ($this->cat == 'all' or $this->cat == null) { $query = Logotypes::find(); } else { $query_cat = new Query(); $query_cat->select('id')->from('category')->where(['name' => $this->cat]); $cat_id = $query_cat->all()[0]['id']; $query = Logotypes::find()->where(['category' => $cat_id]); } $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 15]); $logos = $query->offset($pages->offset)->limit($pages->limit)->all(); $this->pages = $pages; } $this->logos = $logos; }
public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Logotypes::find(), 'pagination' => ['pageSize' => 10]]); return $this->render('index', ['dataProvider' => $dataProvider]); }