public function run() { $news = News::getDb()->cache(function () { return News::find()->orderBy('dt_add DESC')->limit(4)->all(); }); return $this->render('last_news', ['news' => $news]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'dt_add' => $this->dt_add, 'status' => $this->status]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'tags', $this->tags])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }