0

每个 bjyauthorize.global 文件都有一个“允许”部分,其中包含一个数组。

'rule_providers' => array(
    'BjyAuthorize\Provider\Rule\Config' => array(
        'allow' => array(
            // allow guests and users (and admins, through inheritance)
            // the "wear" privilege on the resource "pants"
            array(array('guest', 'user'), 'pants', 'wear')
        ),

        'deny' => array(
            // ...
        ),
    ),
),

该数组包含所有允许的角色。但是这些角色是硬编码的。我只想通过函数从表中返回这些数组集。我该怎么做??..请指教.....

4

2 回答 2

0

嘿,我找到了答案......这可以通过覆盖 bjyauthorize 规则和资源类来简单地完成。通过 bjyauthorize.global.php 输入的数组分别被过滤到它的规则和资源类中。无需硬编码,只需编写自己的资源和规则类,并在其 get 方法中,打开表网关,连接到数据库并引入信息....:)

于 2014-04-11T18:22:34.200 回答
0

好吧。可能有多种方法可以实现这一点,我很确定你会在这里和那里遇到麻烦,但你可以在 module.php 的 onBootstrap 方法中覆盖配置。

../Project/module/Application/Module.php

public function onBootstrap(MvcEvent $e) {
    $eventManager = $e->getApplication()->getEventManager();
    $serviceManager = $e->getApplication()->getServiceManager();
    $config = $serviceManager->get('Config');
    // You'll need to get the information from the DB here
    var_dump($config['bjyauthorize']['rule_providers']);exit;
}

从这里开始你应该没问题,只需从你的数据库中获取信息并$config['bjyauthorize']['rule_providers']用你在数据库中的角色覆盖。

编辑:我不熟悉 bjyauthorize 模块,但我很确定它有添加或删除 ACL 条目的方法。窥视模块代码并查看是否可以找到任何和/或它在其服务中提供任何方法可能是一个好主意。如果确实如此,那么它可能是一个更好的解决方案,然后覆盖配置。

于 2014-03-20T09:06:03.523 回答