/**
  * Assign or remove items
  * @param array $routes
  * @return array
  */
 public function remove($routes)
 {
     $manager = Yii::$app->getAuthManager();
     foreach ($routes as $route) {
         try {
             $item = $manager->createPermission('/' . trim($route, '/'));
             $manager->remove($item);
         } catch (Exception $exc) {
             Yii::error($exc->getMessage(), __METHOD__);
         }
     }
     Helper::invalidate();
 }
 /**
  * Revokes a roles from a user.
  * @param array $items
  * @return integer number of successful revoke
  */
 public function revoke($items)
 {
     $manager = Yii::$app->getAuthManager();
     $success = 0;
     foreach ($items as $name) {
         try {
             $item = $manager->getRole($name);
             $item = $item ?: $manager->getPermission($name);
             $manager->revoke($item, $this->id);
             $success++;
         } catch (\Exception $exc) {
             Yii::error($exc->getMessage(), __METHOD__);
         }
     }
     Helper::invalidate();
     return $success;
 }
 /**
  * Remove an item as a child of another item.
  * @param array $items
  * @return int
  */
 public function removeChildren($items)
 {
     $manager = Yii::$app->getAuthManager();
     $success = 0;
     if ($this->_item !== null) {
         foreach ($items as $name) {
             $child = $manager->getPermission($name);
             if ($this->type == Item::TYPE_ROLE && $child === null) {
                 $child = $manager->getRole($name);
             }
             try {
                 $manager->removeChild($this->_item, $child);
                 $success++;
             } catch (\Exception $exc) {
                 Yii::error($exc->getMessage(), __METHOD__);
             }
         }
     }
     if ($success > 0) {
         Helper::invalidate();
     }
     return $success;
 }
 /**
  * Deletes an existing AuthItem model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param  string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     Yii::$app->getAuthManager()->remove($model->item);
     Helper::invalidate();
     return $this->redirect(['index']);
 }
示例#5
0
 /**
  * Deletes an existing Menu model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param  integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     Helper::invalidate();
     return $this->redirect(['index']);
 }