vmorozov/yii2-entrust
Composer 安装命令:
composer require vmorozov/yii2-entrust
包简介
Roles and permissions system like zizaco/entrust in laravel for yii2.
README 文档
README
Roles and permissions system like zizaco/entrust in Laravel for Yii2.
##Description
This plugin helps you to manage users roles and permissions very fast and easily.
####For complex roles systems
Roles are presets of permissions. So it means that you have independent control of each user permissions.
So after assigning role to some user will assign all permissions assigned to role to this user.
You can check permission of user with hasPermission()
####For very simple roles systems
You can use only roles to check if user has rights for the action with hasRole() method
##Installation
#####IMPORTANT!
#####Before installing this plugin you should have fully configured User model to work with database.
#####And you should have table with users with any name attached to User model in your database.
#####In the other case you will get the error while running plugin migration.
-
Install with Composer:
composer require vmorozov/tii2-entrust dev-master -
Run migrations to create rbac tables
php yii migrate/up --migrationPath=@vendor/vmorozov/yii2-entrust/migrations -
Put given code to User model:
use vmorozov\entrust\traits\EntrustUserTrait; class User extends ActiveRecord implements IdentityInterface { use EntrustUserTrait; // insert this line .... }
##Usage
####Create role and Permission
// create role $adminRole = new Role(); $adminRole->attributes = [ 'name' => 'admin', // short name for use in code 'display_name' => 'Admin', // More beautiful name to display it to users if it is needed 'description' => 'Administrator (has all permissions)', // Description of role ]; $adminRole->save(); // create permission $create_post_permission = new Permission(); $create_post_permission->attributes = [ 'name' => 'create_post', // short name for use in code 'display_name' => 'Create Post', // More beautiful name to display it to users if it is needed 'description' => 'Permission to create new post', // Description of permission ]; $create_post_permission->save();
####Assign Permissions to Role
// add permission to role with permission name string $adminRole->attachPermission('create_post'); // add permission to role with permission object $adminRole->attachPermission($create_post_permission); // remove permission from role with permission name string $adminRole->detachPermission('create_post'); // remove permission from role with permission object $adminRole->detachPermission($create_post_permission);
####Assign Role To User
$user->assignRole($adminRole); // $adminRole must be a Role object
####Assign Permissions Directly To User
// add permission to user with permission name string $user->attachPermission('create_post'); // add permission to user with permission object $user->attachPermission($create_post_permission); // remove permission from user with permission name string $user->detachPermission('create_post'); // remove permission from user with permission object $user->detachPermission($create_post_permission);
####Check if user has permission
$user->hasPermission('create-post'); // returns true if user has permission with given name
####Check if user has role Commonly this method is used in simple roles systems where there are no permissions, only roles.
$user->hasRole('admin'); // returns true if user has role with given name
####Get Permissions Of User
// get permissions relation of user. You can manipulate with it as you want. $user->permissions() // get all permissions of user $user->permissions()->all() // configure getting permissions with sql query methods $user->permissions()->where(['like', 'name', 'test%'])->all()
####Get user role
$role = $user->role(); // returns vmorozov\entrust\models\Role Object
vmorozov/yii2-entrust 适用场景与选型建议
vmorozov/yii2-entrust 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 56 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「module」 「extension」 「Users」 「roles」 「permissions」 「rbac」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vmorozov/yii2-entrust 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vmorozov/yii2-entrust 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vmorozov/yii2-entrust 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
Debugging a problem and need to login as one of your customers? This allows you to authenticate as any of your customers.
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
A trait for Laravel models which have many users with roles.
The library provides a flexible way to add role-based access control management to CakePHP 3.x
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
统计信息
- 总下载量: 56
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-02-23