/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = RgnDistrict::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, 'city_id' => $this->city_id]); $query->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'number', $this->number])->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = RgnDistrict::find()->with('city'); $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_district.id' => $this->id]); $query->andFilterWhere(['like', 'rgn_district.recordStatus', $this->recordStatus])->andFilterWhere(['like', 'rgn_district.number', $this->number])->andFilterWhere(['like', 'rgn_district.name', $this->name]); if (is_integer($this->city_id)) { $query->andFilterWhere(['city_id' => $this->city_id]); } else { if ($this->city_id) { $query->joinWith(['city' => function ($q) { $q->where('rgn_city.name LIKE "%' . $this->city_id . '%"'); }]); } } return $dataProvider; }