是根据yii2-admin(https://github.com/mdmsoft/yi...)修改的,yii2-admin只是一个web方法,这相当于yii2-admin的其余版本。适用于前后端分离项目,以rest方式提供接口,实现对接口的权限控制。项目地址:https://github.com/windhoney/...yii2-rest-rbacYii2权限系统,rest版本,根据yii2-admin(https://github.com/mdmsoft/yii2-admin)修改安装:composer需要windhoney/yii2-rest-rbac配置oauth2和rbac'modules'=>['rbac'=>['class'=>'wind\rest\modules'],'oauth2'=>['class'=>'filsh\yii2\oauth2server\Module','tokenParamName'=>'access_token','tokenAccessLifetime'=>3600*24,'storageMap'=>['user_credentials'=>'backend\models\User',],'grantTypes'=>['user_credentials'=>['class'=>'OAuth2\GrantType\UserCredentials',],'client_credentials'=>['class'=>'OAuth2\GrantType\ClientCredentials',],'refresh_token'=>['class'=>'OAuth2\GrantType\RefreshToken','always_issue_new_refresh_token'=>true],'authorization_code'=>['class'=>'OAuth2\GrantType\AuthorizationCode'],],'components'=>['request'=>function(){return\filsh\yii2\oauth2server\Request::createFromGlobals();},'response'=>['class'=>\filsh\yii2\oauth2server\Response::class,],],]],'components'=>['authManager'=>['class'=>'wind\rest\components\DbManager',//配置文件],]配置权限'asaccess'=>['class'=>'wind\rest\components\AccessControl','allowActions'=>['site/*',//允许访问的节点,可以添加'rbac/menu/user-menu','oauth2/*',]],创建需要的表1.用户表用户和菜单表menuyiimigrate--migrationPath=@vendor/windhoney/yii2-rest-rbac/migrations2。rbac相关权限表yiimigrate--migrationPath=@yii/rbac/migrations/auth_itemtableaddafieldparent_namevarchar(30)COLLATEutf8_unicode_ciDEFAULT''COMMENT'Parentname',3.oauth2相关表yiimigrate--migrationPath=@vendor/filsh/yii2-oauth2-server/migrations4.新建组表CREATETABLE`auth_groups`(`group_id`varchar(50)NOTNULLCOMMENT'groupid',`group_name`varchar(100)NOTNULLDEFAULT''COMMENT'groupname',`group_status`varchar(50)NOTNULLDEFAULT''COMMENT'status(on,off)',PRIMARYKEY(`group_id`))ENGINE=InnoDBDEFAULTCHARSET=utf8COMMENT='Group';CREATETABLE`auth_groups_child`(`id`int(11)NOTNULLAUTO_INCREMENT,`group_id`varchar(50)NOTNULLCOMMENT'groupid',`user_id`varchar(64)NOTNULLCOMMENT'userid',PRIMARYKEY(`id`),UNIQUEKEY`group_id_2`(`group_id`,`user_id`),KEY`group_id`(`group_id`),KEY`user_group_id`(`user_id`)使用BTREE)ENGINE=InnoDBAUTO_INCREMENT=795DEFAULTCHARSET=utf8COMMENT='组子集';添加路由配置在项目的urlManager规则下配置yii2-rest-rbac/example/rbac_route.php文件的内容或者在main.php文件中添加$dir=__DIR__。"/route";$main=wind\rest\helper\RbacHelper::addRoute($dir,$main);return$main;并将此文件放入config/route/rbac_route.php接口文档参考文档
