public function actionDistricts() { $country = Yii::$app->request->post('country'); if (empty($country) || $country === 'undefined') { return null; } $province = Yii::$app->request->post('province'); if (empty($province) || $province === 'undefined') { return null; } $city = Yii::$app->request->post('city'); if (empty($city) || $city === 'undefined') { return null; } return District::asArray(Country::get($country)->getProvince($province)->getCity($city)->districts); }
protected function populateRegion() { $region = ""; $country = Country::get($this->model->country); if (!$country) { return $region; } $region .= $country->shortname; $province = $country->getProvince($this->model->province); if (!$province) { return $region; } $region .= " " . $province->localname; $city = $province->getCity($this->model->city); if (!$city) { return $region; } $region .= " " . $city->localname; $district = $city->getDistrict($this->model->district); if (!$district) { return $region; } return $region . " " . $district->localname; }
/** * @return \yii\db\ActiveQuery */ public function getCountry0() { return $this->hasOne(Country::className(), ['alpha2' => 'country']); }