我在实施 ZfcRbac 时遇到问题。目前 Rbac 工作,我在某个 url 上输入一个页面,我将收到 403。我用于此的代码如下:
'zfc_rbac' => array(
'guards' => array(
'ZfcRbac\Guard\RouteGuard' => array(
'relation*' => array('relation'),
),
),
'role_provider' => array(
'ZfcRbac\Role\InMemoryRoleProvider' => array(
'relation' => array(
'permissions' => array('view', 'edit', 'delete'),
),
),
),
),
当我尝试让它与 Zend Navigation 助手交谈时,就会出现问题。由于一些奇怪的原因,导航一直告诉我它可以访问该页面。当我点击它时,你似乎不能。这是一些检查它的代码
public function onBootstrap(MvcEvent $e)
{
$application = $e->getApplication();
$serviceManager = $application->getServiceManager();
$sharedEvents = $application->getEventManager()->getSharedManager();
$authorization = $serviceManager->get('ZfcRbac\Service\AuthorizationService');
$sharedEvents->attach(
'Zend\View\Helper\Navigation\AbstractHelper', 'isAllowed', function (EventInterface $e) use ($authorization)
{
$page = $e->getParam('page');
$permission = $page->getPermission();
return $authorization->isGranted($permission);
}
);
}
视图助手将被称为:
<?=$this->navigation('navigation')->menu()->setPartial(array('sidebar.phtml', 'css'=>'nav navbar-nav'))->render();?>
希望有人知道这个问题的答案。
提前致谢。