/** * Integrates the country registry. */ protected function integrateCountry() { $country = new Country(['name' => 'España', 'code' => 'es']); if ($country->save() === false) { throw new SaveException($country); } $this->countryId = $country->id; }
/** * Finds the Country model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Country the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findCountry($id) { if (($model = Country::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * @return ActiveDataProvider */ public function search($params) { $query = Country::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function run() { echo $this->form->field($this->model, $this->model->getCountryPropertyName())->dropDownList(ArrayHelper::map(Country::find()->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), ['id' => 'location_country_id', 'prompt' => Yii::t('common/geo/country', 'Select country')]); if ($this->localized === $this->model->getCountryPropertyName()) { return; } echo $this->form->field($this->model, $this->model->getRegionPropertyName())->widget(DepDrop::className(), ['options' => ['id' => 'location_region_id', 'placeholder' => Yii::t('common/geo/region', 'Select region')], 'data' => ArrayHelper::map(Region::find()->where(['country_id' => $this->model->country_id])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), 'pluginOptions' => ['url' => Url::to(['/geo/region/list']), 'depends' => ['location_country_id']]]); if ($this->localized === $this->model->getRegionPropertyName()) { return; } echo $this->form->field($this->model, $this->model->getCityPropertyName())->widget(DepDrop::className(), ['options' => ['id' => 'location_city_id', 'cityholder' => Yii::t('common/geo/city', 'Select city')], 'data' => ArrayHelper::map(City::find()->where(['region_id' => $this->model->region_id])->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), 'pluginOptions' => ['url' => Url::to(['/geo/city/list']), 'depends' => ['location_region_id']]]); if ($this->localized === $this->model->getCityPropertyName()) { return; } echo $this->form->field($this->model, 'address')->textInput(); }
/** * @return \yii\db\ActiveQuery */ public function getCountry() { return $this->hasOne(Country::className(), ['id' => 'country_id']); }
/** * Returns the table name of the Country model. You can override this * method in order to provide a custom table name. * * @return string */ protected function getCountryTableName() { return Country::tableName(); }
/** * Renders the country part. */ protected function country() { $this->parts['{country}'] = $this->form->field($this->model, $this->model->getCountryPropertyName())->dropDownList(ArrayHelper::map(Country::find()->orderBy(['name' => SORT_ASC])->all(), 'id', 'name'), ['id' => 'location_country_id', 'prompt' => Yii::t('jlorente/location', 'Select country')]); }