0

I want Navigation to show only items allowed by Acl, but I have problems linking Navigation with Acl - when I do it, like it is shown in the official example or some other resources on the internet, my navigation still shows all the items like without Acl.

In the Bootstrap, I am doing :

$view->navigation()->setContainer($container);
$view->navigation()->setAcl($acl)->setRole("1");

Where :

  • $view is Zend_View object
  • $container is Zend_Navigation object
  • $acl is Zend_Acl object

I have the initial navigation array set up as it should, acl and navigation objects also seem fine and contain what they should contain, so I am not going to post them here.


At the moment we got it working using constructions like :

if(!$acl->isAllowed(/* auth data, controller, action */)) {
    unset(/* this page from pages array */);
}

but this is not pretty at all and not like a one-liner in the official example.


My question is what is most likely my problem here and what are most usual problems and mistakes that developers make while combining Zend_Navigation with Zend_Acl?

Maybe I can find a solution among those and this could help other developers who are having problems with this issue.

tereško
  • 58,060
  • 25
  • 98
  • 150
bogatyrjov
  • 5,317
  • 9
  • 37
  • 61
  • Additional question is about setRole("1") - currently I am passing the id of the role to it, as the role arrays contain only ids. Is that correct usage of setRole() ? – bogatyrjov Oct 19 '12 at 09:49

1 Answers1

1

I have a suggestion. Why can't you write a view helper for that(with module,controller,action as parameters)?And in that view helper you can check access.

So instead of simply redirecting, you can use the viewhelper to check the access and forward to the action.

Is this what you are looking for?

harry
  • 1,410
  • 3
  • 12
  • 31