/** * Updates an existing AuthItem 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); $parent = AuthItemChild::find()->where(['child' => $model->name])->one(); if (Yii::$app->request->isPost) { $oldRole = $model->name; if ($model->load(Yii::$app->request->post()) && $model->validate()) { $role = $this->auth->getRole($oldRole); if (empty($role)) { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Jabatan Gagal Diubah')); } else { $role->name = $model->name; $role->description = $model->description; $role->data = Yii::$app->request->post('routers'); $role->ruleName = $model->rule_name; $this->auth->update($oldRole, $role); Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Data Jabatan Berhasil Diubah')); return $this->redirect(['index']); } } else { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Jabatan Gagal Diubah')); } } $routers = RouterGenerator::run(); ksort($routers); $children = AuthItem::find()->all(); $rule = AuthRule::find()->all(); return $this->render('update', ['model' => $model, 'routers' => $routers, 'registeredRouters' => $this->auth->getRole($model->name), 'children' => $children, 'rule' => $rule, 'parent' => $parent]); }