Zend Navigation Helper不与ZfcRbac通信

时间:2014-03-03 14:45:51

标签: zend-framework2 zfc-rbac

我在实现ZfcRbac时遇到了问题。在Rbac工作的那一刻,我在某个网址上输入一个页面,我将收到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();?>

希望有人知道这个问题的答案。

提前致谢。

0 个答案:

没有答案