Download the PHP package jackchow/rbac without Composer

On this page you can find all versions of the php package jackchow/rbac. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package rbac

Rbac (ThinkPHP 5 Package)

Rbac是向ThinkPHP 5添加基于角色的权限的简洁而灵活的方式。

Contents

安装

运行 composer require jackchow/rbac

项目用到TP的migrate扩展包。(Tip:命令运行失败请检查该包是否安装)点击了解

配置

您还可以发布此包的配置以进一步自定义表名称和模型名称空间。 在application/command.php文件中添加下面代码(生成命令):

然后使用php think rbac:publish 生成配置文件rbac.php 在config目录下。

config/rbac.php 文件中设置属性值. 委托使用这些值来引用正确的用户表和模型.

用户与角色的关系

刚刚在上面注册了Rbac的生成命令后,现在就可以使用命令生成Rbac的迁移文件:

它将生成<timestamp>_rbac.php 迁移文件 和 RbacSeeder.php数据填充文件.

生成迁移文件位置在:\database\migrations 中

现在您可以根据自己的需求修改迁移文件

如果你修改了迁移文件中某些表的字段 记得也要在seed文件中修改对应的数值,不然seed填充可能会出现无法预测的错误。

然后您现在可以使用think migrate 和 think seed 命令运行它:

迁移后,将出现五个新表格:

如果系统已经存在admins表 可以在生成的迁移文件注释相应的迁移代码。

小提示一下:如果你已经执行了迁移命令,又想修改迁移文件。可以使用命令think migrate:rollback回滚一下

如果你还没有创建admin模块 可以使用命令php think build --module admin生成

hhh,相信你已经懂了.

模型

Role

使用以下示例在application\admin\model\Roles.php内创建角色模型:

角色模型有三个主要属性:

Permission

使用以下示例在application\admin\model\Permissions.php内创建角色模型:

“权限”模型与“角色”具有相同的两个属性:

Admin

接下来,在现有的Admin模型中使用RbacUserTrait特征。 例如:

这将启用与Role的关系,并在User模型中添加以下方法roles()和 can($ permission)

不要忘记转储composer的自动加载

准备好了.

使用

概念

让我们从创建以下角色权限开始:

接下来,让我们为刚刚创建的两个角色将它们分配给用户。 这很容易:

现在我们只需要为这些角色添加权限:

检查用户是否拥有权限

现在我们可以通过执行以下操作来检查角色和权限:

小提示:本功能在保存用户和角色之间的关系和角色与权限之间的关系,为了避免大量的sql查询是使用了tp的缓存的哦,

如果你更新了他们之间的关系,记得把缓存清理一下。它们的缓存键名分别是 rbac_roles_for_user_用户表主键值(参考值:1)rbac_permissions_for_role_角色表主键值(参考值:1)

到目前为止,已经可以很大的满足到后台用户权限管理功能了。

本功能目前比较简单,现在作者正在扩展其他功能.

最后,如果你觉得不错,请start一个吧 你的鼓励是我创作的无限动力.

故障排查

如果你迁移和配置中遇到问题,可直接联企鹅号:775893055

License

Rbac is free software distributed under the terms of the MIT license.

Contribution guidelines

Support follows PSR-1 and PSR-4 PHP coding standards, and semantic versioning.

Please report any issue you find in the issues page.
Pull requests are welcome.


All versions of rbac with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.0
topthink/think-migration Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jackchow/rbac contains the following files

Loading the files please wait ....