/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Topic::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(['topic_id' => $this->topic_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'author_id' => $this->author_id, 'category_id' => $this->category_id, 'title_content' => $this->title_content, 'topic_image' => $this->topic_image]); $query->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'title', $this->title_content])->andFilterWhere(['like', 'data', $this->data]); 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) { if (Yii::$app->user->can('admin')) { if (($model = Topic::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } else { $this->goHome(); } }