/** * Конструктор класса который инициализирует его через townId * @return Place * null если страна не найдена */ public static function findTown($id) { $town = Town::find($id); if (is_null($town)) { return null; } $instance = new Place(); $instance->town = $town; $region = Region::find($town->getRegionId()); if (is_null($region)) { return null; } $instance->region = $region; $country = Country::find($region->getCountryId()); if (is_null($country)) { return null; } $instance->country = $country; return $instance; }
private function renderItem($id, $name, \yii\web\View $view, $source, $idInt, $key) { // добавляю опции input'а $optionsName = $key . 'InputOptions'; $inputOptions = $this->{$optionsName}; if (!is_null($inputOptions)) { if (ArrayHelper::keyExists('class', $inputOptions)) { $inputOptions['class'] .= ' form-control ui-autocomplete-input'; } else { $inputOptions['class'] = 'form-control ui-autocomplete-input'; } } else { $inputOptions = ['class' => 'form-control ui-autocomplete-input']; } $attrName = $this->attribute . '_' . $key; $value = null; if ($this->model->hasProperty($attrName)) { $value = $this->model->{$attrName}; if (!is_null($value)) { switch ($key) { case 'town': $value = Town::find($value)->getName(); break; case 'region': $value = Region::find($value)->getName(); break; case 'country': $value = Country::find($value)->getName(); break; } } } return Html::input('text', $name, $value, ArrayHelper::merge($inputOptions, ['id' => $id, 'autocomplete' => 'off'])); }