I have a Zend_Navigation running with data provided by a navigation.xml file. Let's assume the first level (0) consists of two pages, Frontend and Backend. Frontend is accessible by the guest role, Backend only by the admin role.
If I do a
<?php echo $this->navigation()->menu()->setMaxDepth(0); ?>
it correctly displays the "Frontend" link when not logged in, and both the "Frontend" and "Backend" links when logged in as an admin.
However, displaying the "Frontend" link doesn't make much sense for guests, because they don't have any other pages to navigate to on that level anyway. So I would rather not display that navigation at all for guests.
I know I could do
<?php
if ('guest' !== $this->view->role) {
echo $this->navigation()->menu();
}
?>
but I'm hoping for a better way to do this.
What I'm looking for is something like
<?php
if (count($this->navigation()->getPagesForRole($this->view->role)) > 1) {
echo $this->navigation()->menu();
}
?>
I can't figure out how to achieve this with the API provided by Zend_Navigation... I see there is a getPages() method, but it returns all pages "unfiltered".
I assume there is an easy solution to this, but I've been trying to figure this out for the past two hours and found nothing, so I guess I'm looking in the wrong direction.
Thanks for your time.
Edit:
I forgot to mention that the navigation is already using ACL to control privileges, and it's working fine. My only problem is that I do not want to display the Frontend/Backend navigation for the guests, because a navigation of only one link item is pretty useless. Sorry about the confusion.
You can use Zend_ACL for this
Zend_Navigation can work with it