示例#1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdMunicipio()
 {
     return $this->hasOne(Municipio::className(), ['id' => 'id_municipio']);
 }
 /**
  * Updates an existing ProyectoLocalizacion model.
  * For ajax request will return json object
  * and for non-ajax request if update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $request = Yii::$app->request;
     $model = $this->findModel($id);
     //Escenario
     $model->scenario = $this->findAmbito($model->id_proyecto);
     switch ($model->scenario) {
         case 'Nacional':
             $model->id_pais = Pais::findOne(['nombre' => 'Venezuela'])->id;
             break;
         default:
             $model->id_pais = Pais::findOne(['nombre' => 'Venezuela'])->id;
             break;
     }
     //Listas desplegables
     $paises = Pais::find()->all();
     $estados = Estados::find()->all();
     $parroquias = Parroquia::find()->all();
     $municipios = Municipio::find()->all();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['title' => "Update ProyectoLocalizacion #" . $id, 'content' => $this->renderPartial('update', ['model' => $model, 'paises' => $paises, 'estados' => $estados, 'municipios' => $municipios, 'parroquias' => $parroquias]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['forceReload' => 'true', 'title' => "ProyectoLocalizacion #" . $id, 'content' => $this->renderPartial('view', ['model' => $model, 'paises' => $paises, 'estados' => $estados, 'municipios' => $municipios, 'parroquias' => $parroquias]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Edit', ['update', 'id' => $id], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])];
             } else {
                 return ['title' => "Update ProyectoLocalizacion #" . $id, 'content' => $this->renderPartial('update', ['model' => $model, 'paises' => $paises, 'estados' => $estados, 'municipios' => $municipios, 'parroquias' => $parroquias]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('update', ['model' => $model, 'paises' => $paises, 'estados' => $estados, 'municipios' => $municipios, 'parroquias' => $parroquias]);
         }
     }
 }