示例#1
0
 /**
  * Deletes an existing Role model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $_id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $userModel = User::findOne(['role' => $model->name]);
     if (empty($userModel)) {
         try {
             $model->delete();
             Yii::$app->session->setFlash('success', Yii::t('app', 'Role deleted'));
             try {
                 RolePermission::deleteAll(['roleName' => $model->name]);
             } catch (Exception $e) {
             }
         } catch (Exception $e) {
             Yii::$app->session->setFlash('error', Yii::t('app', 'Role delete failed'));
         }
     } else {
         Yii::$app->session->setFlash('error', Yii::t('app', 'Role cannot be deleted. First delete users attached to this role.'));
     }
     return $this->redirect(['index']);
 }
示例#2
0
 /**
  * Deletes an existing Permission model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $_id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     if ($model->delete()) {
         Yii::$app->session->setFlash('success', Yii::t('app', 'Permission deleted'));
         try {
             RolePermission::deleteAll(['permissionName' => $model->name]);
         } catch (Exception $e) {
         }
     } else {
         Yii::$app->session->setFlash('success', Yii::t('app', 'Permission delete failed'));
     }
     return $this->redirect(['index']);
 }