/** * Запуск видежта */ public function run() { $query = Blog::find()->orderBy(['created_at' => SORT_DESC]); $countQuery = clone $query; $totalCount = $countQuery->count(); $blogModels = $query->limit(3)->all(); return $this->render('index', ['blogModels' => $blogModels]); }
public function search($params) { $query = Blog::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $this->addCondition($query, 'id'); $this->addCondition($query, 'title', true); $this->addCondition($query, 'description', true); $this->addCondition($query, 'body', true); $this->addCondition($query, 'status'); $this->addCondition($query, 'category_id'); $this->addCondition($query, 'created_by'); $this->addCondition($query, 'updated_by'); $this->addCondition($query, 'created_at'); $this->addCondition($query, 'updated_at'); return $dataProvider; }