/** * Рендерит html регионов для dropdown * @param int $id идентификатор страны * @throws \yii\base\ExitException */ public function actionRegions($id) { $all = Region::find()->published()->where(["country_id" => $id])->orderBy(["title" => SORT_ASC])->all(); $o = ["prompt" => ""]; echo Html::renderSelectOptions(null, ArrayHelper::map($all, "id", "title"), $o); Yii::$app->end(); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Region::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'pais_id' => $this->pais_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'pais_cd', $this->pais_cd])->andFilterWhere(['like', 'region_cd', $this->region_cd])->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
/** * Связь с регионами * @return \yii\db\ActiveQuery */ public function getRegions() { return $this->hasMany(Region::className(), ["country_id" => "id"])->published(); }
/** * Связь с регионом * @return \yii\db\ActiveQuery */ public function getRegion() { return $this->hasOne(Region::className(), ["id" => "region_id"]); }
public function actionGetCiudadesRegion($region_id, $empty = true) { if ($empty) { $options = ['' => 'Escoge ciudad']; } $ciudades = Region::find()->where(['id' => $region_id])->one()->ciudads; $ciudades = ArrayHelper::map($ciudades, 'id', 'nombre'); asort($ciudades); $options += $ciudades; echo Html::renderSelectOptions('', $options); }
/** * @return \yii\db\ActiveQuery */ public function getRegions() { return $this->hasMany(Region::className(), ['pais_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getRegion() { return $this->hasOne(Region::className(), ['id' => 'region_id']); }
/** * Finds the Region model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Region the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Region::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }