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