2013-08-29 155 views
0

在一个项目中,我使用了不同类型的角色的访问控制列表菜单,但面临着一个问题时,试图做同样的菜单,身兼数职,但对于一些角色我想隐藏一些观点。 文档说,使用“资源”参数数组做到这一点,但我的作品只针对整个上级菜单:不同的子菜单,在ZF2导航不同的用户角色(Zend的导航)

array(
    'label'  => 'Community', 
    'module'  => 'community', 
    'controller' => 'index', 
    'action'  => 'index', 
    'resource' => 'mvc:community' 
    'pages'  => array(
     array(
      'label'  => 'My Account', 
      'module'  => 'community', 
      'controller' => 'account', 
      'action'  => 'index', 
     ), 
     array(
      'label' => 'Forums', 
      'uri' => 'http://forums.example.com/', 
      'class' => 'external' // class 
     ) 
    ) 
) 

但如果我想隐藏从当前菜单中的某些元素:

array(
    'label'  => 'Community', 
    'module'  => 'community', 
    'controller' => 'index', 
    'action'  => 'index', 
    'pages'  => array(
     array(
      'label'  => 'My Account', 
      'module'  => 'community', 
      'controller' => 'account', 
      'action'  => 'index', 
      'resource' => 'mvc:community.account' 
     ), 
     array(
      'label' => 'Forums', 
      'uri' => 'http://forums.example.com/', 
      'class' => 'external' 
     ) 
    ) 
) 

菜单ACL构建代码:

$acl = new \Zend\Permissions\Acl\Acl(); 
$acl->addRole(new \Zend\Permissions\Acl\Role\GenericRole('root')); 
$acl->addRole(new \Zend\Permissions\Acl\Role\GenericRole('guest')); 

$acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource('mvc:community.account')); 

$acl->allow('root', null); 
$acl->allow('guest', null); 
$acl->deny('guest', 'mvc:community.account'); 

所以,当我使用的整个菜单“资源”键时,在孩子使用它,它的工作原理 - 没有。 目前我为每个角色创建了几个几乎相似的数组,并允许/拒绝某个角色的访问权限,但希望找到正确的方式来执行此操作。

回答

0

其实我认为这是一个错误。

的问题是,在当时呈现的菜单,子菜单为在“资源”的条目都没有了。 您可以使用自己的部分解决问题,并在那里为子页面重新添加“资源”条目。 - coure,相当脏的解决方案。