每个bjyauthorize.global文件都有一个包含数组的“allow”部分。
'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(
// ...
),
),
),此数组包含所有允许的角色。但是这些角色是硬编码的。我只想通过函数从table返回那些数组集合。我如何做this??..please建议.....
发布于 2014-03-20 17:06:04
好的。可能有多种方法可以实现这一点,我非常肯定您会在这里和那里遇到麻烦,但是您可以在module.php中覆盖onBootstrap方法中的配置。
../项目/模块/应用程序/模块
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-04-12 02:22:34
嘿,我发现this.......this的答案可以通过覆盖bjyauthorize规则和资源类来简单地完成。通过bjyauthorize.global.php馈送的数组分别被过滤成其规则和资源类。不需要硬编码,只需编写您自己的资源和规则类,并在其get方法中打开一个表网关,连接到DB并引入信息....:)
https://stackoverflow.com/questions/22473628
复制相似问题