[英]Different submenus for different user roles in ZF2 navigation (Zend\Navigation)
在一個項目中,我將ACL菜單用於不同類型的角色,但是當嘗試為多個角色創建相同菜單但對於某些角色卻想隱藏一些要點時遇到了問題。 文檔說在數組中使用'resource'參數可以做到這一點,但它僅對整個父菜單有效:
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');
因此,當我在整個菜單中使用“資源”鍵時,在子菜單中使用它時,它就可以工作-不能。 目前,我為每個角色創建了幾個幾乎相似的數組,並為每個角色允許/拒絕訪問,但希望找到正確的方法。
實際上,我認為這是一個錯誤。
問題在於,在渲染菜單時,子菜單的“資源”條目消失了。 您可以使用自己的局部頁面來解決問題,然后在此處重新添加子頁面的“資源”條目。 -當然,很臟的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.