/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Airports::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, 'user_id' => $this->user_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'airport_code', $this->airport_code])->andFilterWhere(['like', 'airport_name', $this->airport_name])->andFilterWhere(['like', 'country', $this->country])->andFilterWhere(['like', 'city', $this->city]); return $dataProvider; }
/** * @methods GET or POST * @params airport_code * @return array|string|\yii\db\ActiveRecord[] */ public function actionSearchAirport() { $request = Yii::$app->request; if ($request->isGet) { $code = $request->get('airport_code'); } if ($request->isPost) { $code = $request->post('airport_code'); } if (!empty($code)) { $search_results = Airports::find()->where(['like', 'airport_code', $code])->asArray()->all(); if (!empty($search_results)) { return $search_results; } else { return 'No match found against airport_code'; } } else { return 'Invalid Parameter'; } }