php - Zend_Navigation: Getting Only the Pages Accessible by the Current User/Role -
i have zend_navigation running data provided navigation.xml file. let's assume first level (0) consists of 2 pages, frontend , backend. frontend accessible guest role, backend admin role.
if a
<?php echo $this->navigation()->menu()->setmaxdepth(0); ?>
it correctly displays "frontend" link when not logged in, , both "frontend" , "backend" links when logged in admin.
however, displaying "frontend" link doesn't make sense guests, because don't have other pages navigate on level anyway. rather not display navigation @ guests.
i know do
<?php if ('guest' !== $this->view->role) { echo $this->navigation()->menu(); } ?>
but i'm hoping better way this.
what i'm looking like
<?php if (count($this->navigation()->getpagesforrole($this->view->role)) > 1) { echo $this->navigation()->menu(); } ?>
i can't figure out how achieve api provided zend_navigation... see there getpages() method, returns pages "unfiltered".
i assume there easy solution this, i've been trying figure out past 2 hours , found nothing, guess i'm looking in wrong direction.
thanks time.
edit:
i forgot mention navigation using acl control privileges, , it's working fine. problem not want display frontend/backend navigation guests, because navigation of 1 link item pretty useless. sorry confusion.
zend navigation requires zend_acl instance achieve that. have adjust navigation config include resource/privilege information, e.g.
$navarray = array( …, array( 'module' => 'admin', 'label' => 'administration', 'resource' => 'admin', 'privilege' => 'index', 'pages' => array( … );
see http://framework.zend.com/manual/en/zend.navigation.containers.html
then need set acl defining access restrictions resources , privileges.
$acl = new zend_acl(); $acl->addrole(new zend_acl_role('user')) ->addrole(new zend_acl_role('admin')); …
see http://framework.zend.com/manual/en/zend.acl.introduction.html
your acl has set navigation helper, along role of current user
$this->gethelper('navigation') ->setacl($acl) ->setrole('user');
after that, calls helper api should aware of acl. in above example, admin menu should not rendered, if user disallowed access in acl.
additional resources:
Comments
Post a Comment