I have a working ACL module and Navigation setup in a Zend Framework 2 project.
The navigation object is generated and rendered properly, but it contains an element admin
that I only want to be rendered when the logged in user has the role admin. The acl is properly blocking access (i.e. redirects to 403 page) when a non-admin tries to access any pages there, however the navigation still renders the nav-item.
The navigation setup is very simple (as it should be based on the read tutorials)
module.config.php
'service_manager' => array(
'factories' => array(
'navigation' => 'Zend\Navigation\Service\DefaultNavigationFactory',
),
),
view.phtml
<div id="navigation">
<?php echo $this->navigation('navigation')
->menu()
->setMinDepth(0)
->setMaxDepth(0)
->setAcl($this->acl)
->setRole('guest'); ?>
</div>
After a lot of debugging, I pinpointed where something is going wrong but I have no clue why or how to fix it. I tried var_dumping $this->acl
in the view and it is set, as expected. However:
var_dump($this->navigation('navigation')->getAcl());
after the line with setAcl()
, returns NULL
. So somehow it seems that setAcl($this->acl)
is not actually injecting the acl.
Zend/View/Helper/Navigation/AbstractHelper.php
the functionaccept
is checking the acl for page and role. Acl and role are set properly but stillaccept
is returningtrue
for all resources for every role.accept
calls the functionisAllowed()
which calls$this->getEventManager()->trigger(__FUNCTION__, $this, $params)
but I have no idea what this does – Pankrates