public function putActualizarDepartamento() { $newDepart = Request::input('departamento'); $city = Ciudad::find(Request::input('id')); DB::table('ciudades')->where('departamento', $city->departamento)->update(['departamento' => $newDepart]); return $city; }
/** * Obtener las ciudades de una determinada Provincia. * @param integer $provincia_id * */ public function actionCiudadesPorProvincia($provincia_id) { $items = []; if (!empty($provincia_id)) { $items = ArrayHelper::map(Ciudad::find()->where(['provincia_id' => $provincia_id])->orderBy('nombre ASC')->asArray()->all(), 'id', 'nombre'); } return \yii\helpers\Json::encode($items); }
public function getDatosciudad($ciudad_id) { $ciudad = Ciudad::find($ciudad_id); $pais = $this->getPaisdeciudad($ciudad->id); $departamentos = $this->getDepartamentos($pais[0]->id); $ciudades = Ciudad::where('departamento', $ciudad->departamento)->get(); $result = array('ciudad' => $ciudad, 'ciudades' => $ciudades, 'departamento' => array('departamento' => $ciudad->departamento), 'departamentos' => $departamentos, 'pais' => $pais[0], 'paises' => Pais::all()); return $result; }
public function search($params) { $query = Ciudad::find()->joinWith('provincia')->joinWith('pais'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->getSort()->attributes = array_merge($dataProvider->getSort()->attributes, ['pais_nombre' => ['asc' => ['pais.nombre' => SORT_ASC], 'desc' => ['pais.nombre' => SORT_DESC], 'label' => Yii::t('app', 'País')], 'provincia_nombre' => ['asc' => ['provincia.nombre' => SORT_ASC], 'desc' => ['provincia.nombre' => SORT_DESC], 'label' => Yii::t('app', 'Provincia')]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'pais.nombre', $this->pais_nombre])->andFilterWhere(['like', 'pais.nombre', $this->pais_nombre])->andFilterWhere(['like', 'provincia.nombre', $this->provincia_nombre]); return $dataProvider; }
?> <?php echo $form->field($model, 'ciudad_id')->dropDownList(['' => 'Seleccione una Provincia'], ['prompt' => '']); ?> <?php } else { ?> <?php echo $form->field($model, 'provincia_id')->dropDownList(ArrayHelper::map(Provincia::find()->where(['pais_id' => $model->pais_id])->innerJoinWith('ciudades')->orderBy('nombre ASC')->asArray()->all(), 'id', 'nombre')); ?> <?php echo $form->field($model, 'ciudad_id')->dropDownList(ArrayHelper::map(Ciudad::find()->where(['provincia_id' => $model->provincia_id])->innerJoinWith('provincia')->orderBy('nombre ASC')->asArray()->all(), 'id', 'nombre')); ?> <?php } ?> <?php echo $form->field($model, 'cp')->textInput(['maxlength' => 30]); ?> <?php echo $form->field($model, 'observaciones')->textArea(['maxlength' => 255]); ?> <div class="form-group">