/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = RgnProvince::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'country_id' => $this->country_id]); $query->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'number', $this->number])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'abbreviation', $this->abbreviation]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = RgnProvince::find()->with('country'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['rgn_province.id' => $this->id]); $query->andFilterWhere(['like', 'rgn_province.recordStatus', $this->recordStatus])->andFilterWhere(['like', 'rgn_province.number', $this->number])->andFilterWhere(['like', 'rgn_province.name', $this->name])->andFilterWhere(['like', 'rgn_province.abbreviation', $this->abbreviation]); if (is_integer($this->country_id)) { $query->andFilterWhere(['country_id' => $this->country_id]); } else { if ($this->country_id) { $query->joinWith(['country' => function ($q) { $q->where('rgn_country.name LIKE "%' . $this->country_id . '%"'); }]); } } return $dataProvider; }