/** * Создает DataProvider на основе переданных данных * @param $params - параметры * @return ActiveDataProvider */ public function search($params) { $query = City::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $this::COUNT]]); $this->load($params); // Если валидация не пройдена, то ничего не выводить if (!$this->validate()) { $query->where('0=1'); return $dataProvider; } // Фильтрация $query->andFilterWhere(['id' => $this->id, 'country_id' => $this->country_id, 'biggest_city' => $this->biggest_city]); $query->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'state', $this->state])->andFilterWhere(['like', 'region', $this->region]); return $dataProvider; }
/** * Поиск модели (насленного пункта) по ID * @param integer $id * @return City the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = City::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('user', 'Запрашиваемая страница не найдена.')); } }
/** * Город * @return \yii\db\ActiveQuery */ public function getCity() { return $this->hasOne(City::className(), ['id' => 'city_id']); }