xiaopig 2016-05-03 16:25:00 7551次浏览 5条回复 0 1 0

Yii2的rbac中auth_rule这张表有什么用?具体怎么用?网上都是些入门用法,求大神分享rbac的高级用法。

觉得很赞
  • 回复于 2016-05-04 09:37 举报

    没人理我,看来大家都不懂啊!

    觉得很赞
  • 回复于 2016-10-19 16:00 举报

    帅哥,这张表用了吗?咋用的,是不是用来控制具体数据,id之类的啊

  • 回复于 2017-05-04 13:29 举报

    规则表:[auth_rule]
    一个用户要执行一个操作除了要看他有没有这个权限外,还要看他的这个权限能不能执行。
    在上面的 表:auth_item 中还有一个字段: [rule_name] 。这个字段用来标明这个角色或者权限能不能成功执行。
    那么规则这个表里面的数据是从哪里来的呢?
    下面这个是规则的基类:

    abstract class Rule extends Object
    {

    /**
     * @var string name of the rule
     */
    public $name;
    /**
     * @var integer UNIX timestamp representing the rule creation time
     */
    public $createdAt;
    /**
     * @var integer UNIX timestamp representing the rule updating time
     */
    public $updatedAt;
    
    /**
     * Executes the rule.
     *
     * @param Item $item the auth item that this rule is associated with
     * @param array $params parameters passed to [[ManagerInterface::allow()]].
     * @return boolean a value indicating whether the rule permits the auth item it is associated with.
     */
    abstract public function execute($item, $params);
    

    }

    $name 为规则的名称。
    也就是说如果要在 规则表:[auth_rule] 中增加一条规则就得要有对应的规则类,并实现方法 abstract public function execute($item, $params) 具体的逻辑来判定$item(角色或者权限)是否可执行。

    觉得很赞
  • 回复于 2017-11-12 12:18 举报

    比如写一篇文章,所有作者都有修改文章的权限。但是只能修改自己的文章,就可以设置rule,如果判定如果文章是自己的,才可以修改

您需要登录后才可以回复。登录 | 立即注册