/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, CommentQuery $query = null) { $query === null && ($query = Comment::find()); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'fid' => $this->fid, 'tid' => $this->tid, 'author_id' => $this->author_id, 'view_count' => $this->view_count, 'comment_count' => $this->comment_count, 'like_count' => $this->like_count, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Finds the Topic model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Topic the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id, $type = 'topic', \Closure $func = null) { if ($id) { $model = $type == 'topic' ? Topic::find() : Comment::find(); $model->andWhere(['id' => $id])->active(); $func !== null && $func($model); $model = $model->one(); if ($model !== null) { return $model; } } throw new NotFoundHttpException('The requested page does not exist.'); }