/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Mensagens::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['criado_em' => SORT_DESC]]]); $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_mensagem' => $this->id_mensagem, 'id_destinatario' => Yii::$app->user->getId(), 'lida' => $this->lida, 'resposta_de' => $this->resposta_de, 'criado_por' => $this->criado_por, 'criado_em' => $this->criado_em, 'ativo' => 1]); $query->andFilterWhere(['like', 'texto', $this->texto]); $query->andFilterWhere(['like', 'assunto', $this->assunto]); return $dataProvider; }