/** * Creates a new Kabupaten model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Kabupaten(); if (Yii::$app->request->isPost) { $model->load(Yii::$app->request->post()); $model->autoNumber(); if ($model->validate() && $model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Your data kabupaten has been successfully saved')); return $this->redirect(['create']); } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Your data kabupaten failed to save')); } } return $this->render('create', ['model' => $model]); }
/** * Updates an existing Kelurahan model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $id_prov = ArrayHelper::getValue($model, 'kecamatan.kabupaten.id_prov'); $modelProvinsi = $this->findModelProvinsi($id_prov); $modelProvinsi->scenario = 'DepDrop'; $modelKabupaten = new Kabupaten(['scenario' => 'DepDrop']); if (Yii::$app->request->isPost) { $model->load(Yii::$app->request->post()); $modelProvinsi->load(Yii::$app->request->post()); $modelKabupaten->load(Yii::$app->request->post()); if (Model::validateMultiple([$model, $modelProvinsi, $modelKabupaten]) && $model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Your data kelurahan has been successfully updated')); return $this->redirect(['update', 'id' => $model->id_kel]); } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Your data kelurahan failed to updated')); } } return $this->render('update', ['model' => $model, 'modelProvinsi' => $modelProvinsi, 'modelKabupaten' => $modelKabupaten]); }