Пример #1
0
 /**
  * Возвращает список городов в Json формате
  * AJAX метод
  * @return null
  */
 public function actionGetCityList()
 {
     $id = (int) Yii::$app->request->post('id');
     $input = trim(strip_tags(Yii::$app->request->get('term')));
     $result = City::getCityList($id, $input);
     echo Json::encode($result);
 }
Пример #2
0
 public function validateCityId($attribute, $params)
 {
     $countryId = (int) $this->countryId;
     if (!$countryId) {
         $this->addError('cityName', "Сначала укажите страну.");
     } else {
         $cityList = ArrayHelper::getColumn(City::getCityList($countryId), 'id');
         if (count($cityList) > 0) {
             if (!$this->{$attribute}) {
                 $this->addError('cityName', "Укажите города.");
             } elseif (!in_array($this->{$attribute}, $cityList)) {
                 // TODO добавить отправку уведомления об ошибке с данными на email разработчику
                 $this->addError('cityName', "У указанной страны нет такого города.");
             }
         }
     }
 }