public function actionSetComuna() { $id = Yii::app()->request->getParam('id'); $comuna = Comuna::model()->findAllByAttributes(array('region_id' => $id), array("select" => "nombre,id")); $comunas = '<option value="">Seleccione Region</option>'; foreach ($comuna as $com) { $comunas .= '<option value="' . $com->id . '">' . $com->nombre . '</option>'; } Yii::app()->clientScript->scriptMap['jquery.js'] = false; Yii::app()->clientScript->scriptMap['jquery.min.js'] = false; header("Content-type: application/json"); echo CJSON::encode(array('comuna' => $comunas)); exit; }
<input type="hidden" class="val" value="<?php echo $i; ?> "> <div class="col-md-3"> <?php echo $form->dropDownListGroup($localidad, 'region_id', array('wrapperHtmlOptions' => array('class' => 'col-sm-5'), 'widgetOptions' => array('data' => CHtml::listData(Region::model()->findAll(), 'id', 'nombre'), 'htmlOptions' => array('class' => 'region', 'name' => 'Localidad[' . $i . '][region_id]', 'prompt' => 'Seleccione Region')))); ?> </div> <div class="col-md-3"> <?php echo $form->dropDownListGroup($localidad, 'comuna_id', array('wrapperHtmlOptions' => array('class' => 'col-sm-5'), 'widgetOptions' => array('data' => CHtml::listData(Comuna::model()->findAllByAttributes(array('region_id' => $localidad->region_id), array("select" => "nombre,id")), 'id', 'nombre'), 'htmlOptions' => array('class' => 'comuna', 'name' => 'Localidad[' . $i . '][comuna_id]', 'prompt' => 'Seleccione Comuna')))); ?> </div> <div class="col-md-3"> <?php echo $form->textFieldGroup($localidad, 'direccion', array('wrapperHtmlOptions' => array('class' => 'col-sm-5'), 'widgetOptions' => array('htmlOptions' => array('name' => 'Localidad[' . $i . '][direccion]')))); ?> </div> <?php echo $form->hiddenField($localidad, 'id', array('name' => 'Localidad[' . $i . '][id]')); ?> <?php
<div class="form"> <ul> <li> <?php echo $form->labelEx($direccion, 'direccion_descripcion'); ?> <?php echo $form->textField($direccion, 'direccion_descripcion', array('size' => 60, 'maxlength' => 255)); ?> </li> <li> <?php echo $form->labelEx($direccion, 'comuna_id'); ?> <?php echo $form->dropDownList($direccion, 'comuna_id', CHtml::listData(Comuna::model()->findAll(), 'comuna_id', 'comuna_nombre')); ?> </li> <li> <?php echo CHtml::submitButton('Agregar Dirección'); ?> </li> </ul> </div> <?php $this->endWidget(); ?> </div><!-- form -->
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Comuna the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Comuna::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionAgregarDireccionCliente() { $this->layout = 'ajax'; $comunas = Comuna::model()->findAll(); $direccion = new Direccion(); if (isset($_POST['Direccion'])) { $direccion = new Direccion(); $direccion->attributes = $_POST['Direccion']; $direccion->cliente_id = $_SESSION['Cliente']['cliente_id']; if ($direccion->save()) { Yii::app()->user->setFlash('direccionClienteAgregada', 'La Dirección se ha agregado.'); $this->redirect(array('site/misDireccionesDeEnvio')); } else { Yii::app()->user->setFlash('direccionClienteNoAgregada', 'La Dirección no se ha agregado. Favor intente mas tarde.'); } } $this->render('agregarDireccionCliente', array('comunas' => $comunas, 'direccion' => $direccion)); }