2016-01-23 57 views
-2

使用yii2我可以得到一個擴展,它具有管理基於角色的用戶訪問的物理接口(R.B.A.C.)。獲得更好的yii2 rbac擴展

I have tried using 
mdmsoft, dektrium, yii rbac plus but none has any explanation of how 

建立一個物理上的

回答

0

我已創建管理簡單地使用基於由Yii2提供的defualt RBAC模型提供的表格GII基於角色的用戶物理接口和extendig的相關行動爲作業,角色,項目和item_child插入適當的值。 ..

如:用於創建分配

public function actionCreate() 
{ 
    $model = new AuthAssignment(); 
    $auth = Yii::$app->authManager; 

    if ($model->load(Yii::$app->request->post())) { 

     $auth->assign($auth->getRole($model->item_name), $model->user_id); 
     return $this->redirect(['view', 'item_name' => $model->item_name, 'user_id' => $model->user_id]); 
    } else { 
     return $this->render('create', [ 
      'model' => $model, 
     ]); 
    } 
} 

和創建項目

public function actionCreate() 
{ 
    $model = new AuthItem(); 
    $auth = Yii::$app->authManager; 


    if ($model->load(Yii::$app->request->post())) { 
     switch ($model->type) { 
      case AuthItem::TYPE_ROLE : // 1 = TYPE_ROLE 
       $role = $auth->createRole($model->name); 
       $role->data   = $model->data; 
       //$role->ruleName  = $model->rule_name; 
       $role->description = $model->description; 
       //$role->type   = $model->type; 
       $auth->add($role); 
       break;      
      case AuthItem::TYPE_PERMISSION : // 2 = TYPE_PERMISSION 
       $permission = $auth->createPermission($model->name); 
       $permission->data   = $model->data; 
       //$permission->ruleName  = $model->rule_name; 
       $permission->description = $model->description; 
       //$permission->type   = $model->type; 
       $auth->add($permission); 
       break;    
      default: 
       break; 
     } 
     return $this->redirect(['view', 'id' => $model->name]); 
    } else { 
     return $this->render('create', [ 
      'model' => $model, 
     ]); 
    } 
}