/**
  * 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]);
 }
Example #2
0
 public function actionKabupaten()
 {
     $id_prov = $_POST['depdrop_parents'][0];
     $selected = null;
     if (!empty($_POST['depdrop_params'])) {
         $selected = $_POST['depdrop_params'][0];
     }
     $model = Kabupaten::find()->where(['id_prov' => $id_prov])->all();
     $data = [];
     foreach ($model as $item) {
         $data[] = ['id' => $item->id_kab, 'name' => $item->nama];
     }
     echo Json::encode(['output' => $data, 'selected' => $selected]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Kabupaten::find();
     $query->joinWith(['provinsi']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $dataProvider->sort->defaultOrder = ['id_kab' => SORT_DESC];
     $dataProvider->sort->attributes['nama_provinsi'] = ['asc' => ['provinsi.nama' => SORT_ASC], 'desc' => ['provinsi.nama' => SORT_DESC]];
     $query->andFilterWhere(['like', 'kabupaten.id_kab', $this->id_kab])->andFilterWhere(['like', 'provinsi.nama', $this->nama_provinsi])->andFilterWhere(['like', 'kabupaten.nama', $this->nama]);
     return $dataProvider;
 }
Example #4
0
 public function getKabupatens()
 {
     return $this->hasMany(Kabupaten::className(), ['id_prov' => 'id_prov']);
 }
Example #5
0
 public function getKabupaten()
 {
     return $this->hasOne(Kabupaten::className(), ['id_kab' => 'id_kab']);
 }
 /**
  * Finds the Kabupaten model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Kabupaten the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Kabupaten::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }