with('article'); /** @var ActiveDataProvider $dataProvider */ $dataProvider = Yii::createObject([ 'class' => ActiveDataProvider::className(), 'query' => $query, 'sort' => [ 'defaultOrder' => [ 'id' => SORT_DESC, ] ] ]); $this->load($params); if (! $this->validate()) { return $dataProvider; } $query->andFilterWhere(['like', 'nickname', $this->nickname]) ->andFilterWhere(['status' => $this->status]) ->andFilterWhere(['aid' => $this->aid]) ->andFilterWhere(['like', 'content', $this->content]); if ($this->article_title != '') { $articles = Article::find() ->where(['like', 'title', $this->article_title]) ->select(['id', 'title']) ->indexBy('id') ->asArray() ->all(); $aidArray = []; foreach ($articles as $k => $v) { array_push($aidArray, $k); } $query->andFilterWhere(['aid' => $aidArray]); } $this->trigger(SearchEvent::BEFORE_SEARCH, Yii::createObject(['class' => SearchEvent::className(), 'query'=>$query])); return $dataProvider; } }