/** * 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 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; }
public function destroy($id) { $ciudad = Ciudad::findOrFail($id); $ciudad->delete(); return $ciudad; }
/** * @return \yii\db\ActiveQuery */ public function getCiudad() { return $this->hasOne(Ciudad::className(), ['id' => 'ciudad_id']); }
/** * Finds the Ciudad model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Ciudad the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Ciudad::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function indexAction() { //Example $ciudades = Ciudad::all(); $this->view->ciudades = $ciudades->toArray(); }
/** * @return \yii\db\ActiveQuery */ public function getCiudades() { return $this->hasMany(Ciudad::className(), ['provincia_id' => 'id']); }
public function deleteDestroy($id) { $pro = Ciudad::findOrFail($id); $pro->delete(); return $pro; }
?> <?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">