Example #1
0
 public function save()
 {
     if (!parent::save()) {
         return false;
     }
     $auth = Yii::$app->authManager;
     $role = $auth->getRole($this->item->name);
     if ($this->permissions != null && is_array($this->permissions)) {
         foreach ($auth->getPermissions() as $permission) {
             if (in_array($permission->name, $this->permissions)) {
                 $permission = $auth->getPermission($permission->name);
                 $auth->hasChild($role, $permission) || $auth->addChild($role, $permission);
             } else {
                 $auth->removeChild($role, $permission);
             }
         }
     }
     return true;
 }
Example #2
0
<?php

use johnitvn\rbacplus\models\Role;
$permissions = Role::getPermistions($model->name);
$first = '';
$rows = [];
foreach ($permissions as $permission) {
    if (empty($first)) {
        $first = $permission->name;
    } else {
        $rows[] = '<tr><td>' . $permission->name . '</td></tr>';
    }
}
?>
<div class="permistion-item-view">
    <table class="table table-striped table-bordered detail-view">
        <tbody>
            <tr><th><?php 
echo $model->attributeLabels()['name'];
?>
</th><td><?php 
echo $model->name;
?>
</td></tr>
            <tr><th><?php 
echo $model->attributeLabels()['description'];
?>
</th><td><?php 
echo $model->description;
?>
</td></tr>
Example #3
0
 /**
  * Finds the Role model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $name
  * @return Role the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($name)
 {
     if (($model = Role::find($name)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('rbac', 'The requested page does not exist.'));
     }
 }