2016-02-12 73 views
2

我剛剛發現並開始使用Role Based Access controlyii2 - RBAC - 是否在後端和前端之間共享?

由於我使用yii2的高級模板,我想知道角色和權限是否在後端和前端層之間共享,或者如果它們是分開的。

例如

<?php 
namespace app\commands; 

use Yii; 
use yii\console\Controller; 

class RbacController extends Controller 
{ 
    public function actionInit() 
    { 
     $auth = Yii::$app->authManager; 

     // add "createPost" permission 
     $createPost = $auth->createPermission('createPost'); 
     $createPost->description = 'Create a post'; 
     $auth->add($createPost); 

     // add "author" role and give this role the "createPost" permission 
     $author = $auth->createRole('author'); 
     $auth->add($author); 
     $auth->addChild($author, $createPost); 

    } 
} 

將創作和createpost可用於兩個後端和前端?

謝謝!

+0

在Yii2中最好的Rbac教程www.freetuts.org/tutorial/view?id=6 – SohelAhmedM

回答

4

的RBAC是及部件就共同部分基地。通常如果他們在DB基地使用通用模型和共享相關的數據庫表..

可以聲明在main.php的組件部分這個元素cofig區域,如果你這樣做是常見的DIR兩個環境(前端,後端)之間的正確共享此組件SI和最終所有應用程序之間的你散發你項目C ..

如:普通/配置/ main.php

 'components' => [ 
    ..... 
    'authManager' => [ 
     'class' => 'yii\rbac\DbManager', 
     'cache' => 'cache', 
      .... 
    ], 

這m他們可以自然地在前端和後端之間共享..

+0

非常感謝。這正是我的想法。 – MeV

+1

感謝你..從Yii2的RBAC是非常強大的..良好的工作.. – scaisEdge

+0

我真的很喜歡它..!我肯定會喜歡它..哈哈....謝謝:-) – MeV

相關問題