Все помощники навигации (navigational view helpers) поддерживают ACL через класс Zend\View\Helper\Navigation\HelperAbstract. Объект Zend\Permissions\Acl может быть присоединен к помощнику так: $helper->setAcl($acl), а роли назначаются так: $helper->setRole(‘member’) или $helper->setRole(new ZendPermissionsAclRoleGenericRole(‘member’)). Если ACL используется в помощнике, то назначенная роль должна иметь права доступа к ресурсами страницы и/или иметь привилегии на страницу, которая будет включена при рендеринге.
Если страница не включена в ACL, то и все её потомки так же будут исключены из рендеринга.
Рroxy helper будет инъектить свой собственный ACL и роли в помощники если проксируемым помощникам не были назначены права.
Приведенные ниже примеры показывают, как ACL влияет на рендеринг.
/* * Navigation container (config/array) * Each element in the array will be passed to * ZendNavigationPage::factory() when constructing * the navigation container below. */ $pages = array( array( 'label' => 'Home', 'title' => 'Go Home', 'module' => 'default', 'controller' => 'index', 'action' => 'index', 'order' => -100 // make sure home is the first page ), array( 'label' => 'Special offer this week only!', 'module' => 'store', 'controller' => 'offer', 'action' => 'amazing', 'visible' => false // not visible ), array( 'label' => 'Products', 'module' => 'products', 'controller' => 'index', 'action' => 'index', 'pages' => array( array( 'label' => 'Foo Server', 'module' => 'products', 'controller' => 'server', 'action' => 'index', 'pages' => array( array( 'label' => 'FAQ', 'module' => 'products', 'controller' => 'server', 'action' => 'faq', 'rel' => array( 'canonical' => 'http://www.example.com/?page=faq', 'alternate' => array( 'module' => 'products', 'controller' => 'server', 'action' => 'faq', 'params' => array('format' => 'xml') ) ) ), array( 'label' => 'Editions', 'module' => 'products', 'controller' => 'server', 'action' => 'editions' ), array( 'label' => 'System Requirements', 'module' => 'products', 'controller' => 'server', 'action' => 'requirements' ) ) ), array( 'label' => 'Foo Studio', 'module' => 'products', 'controller' => 'studio', 'action' => 'index', 'pages' => array( array( 'label' => 'Customer Stories', 'module' => 'products', 'controller' => 'studio', 'action' => 'customers' ), array( 'label' => 'Support', 'module' => 'products', 'controller' => 'studio', 'action' => 'support' ) ) ) ) ), array( 'label' => 'Company', 'title' => 'About us', 'module' => 'company', 'controller' => 'about', 'action' => 'index', 'pages' => array( array( 'label' => 'Investor Relations', 'module' => 'company', 'controller' => 'about', 'action' => 'investors' ), array( 'label' => 'News', 'class' => 'rss', // class 'module' => 'company', 'controller' => 'news', 'action' => 'index', 'pages' => array( array( 'label' => 'Press Releases', 'module' => 'company', 'controller' => 'news', 'action' => 'press' ), array( 'label' => 'Archive', 'route' => 'archive', // route 'module' => 'company', 'controller' => 'news', 'action' => 'archive' ) ) ) ) ), 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' // resource ), array( 'label' => 'Forums', 'uri' => 'http://forums.example.com/', 'class' => 'external' // class ) ) ), array( 'label' => 'Administration', 'module' => 'admin', 'controller' => 'index', 'action' => 'index', 'resource' => 'mvc:admin', // resource 'pages' => array( array( 'label' => 'Write new article', 'module' => 'admin', 'controller' => 'post', 'aciton' => 'write' ) ) ) ); // Create container from array $container = new ZendNavigation($pages); // Store the container in the proxy helper: $view->getHelper('navigation')->setContainer($container); // ...or simply: $view->navigation($container);
К приведенному выше примеру идут такие настройки:
// Setup router (default routes and 'archive' route): $front = Zend\Controller\Front::getInstance(); $router = $front->getRouter(); $router->addDefaultRoutes(); $router->addRoute( 'archive', new Zend\Controller\Router\Route( '/archive/:year', array( 'module' => 'company', 'controller' => 'news', 'action' => 'archive', 'year' => (int) date('Y') - 1 ), array('year' => 'd+') ) ); // Setup ACL: $acl = new Zend\Permissions\Acl\Acl(); $acl->addRole(new Zend\Permissions\Acl\RoleGenericRole('member')); $acl->addRole(new Zend\Permissions\Acl\RoleGenericRole('admin')); $acl->add(new Zend\Permissions\Acl\Resource\GenericResource('mvc:admin')); $acl->add(new Zend\Permissions\Acl\Resource\GenericResource('mvc:community.account')); $acl->allow('member', 'mvc:community.account'); $acl->allow('admin', null); // Store ACL and role in the proxy helper: $view->navigation()->setAcl($acl)->setRole('member'); // ...or set default ACL and role statically: Zend\View\Helper\Navigation\HelperAbstract::setDefaultAcl($acl); Zend\View\Helper\Navigation\HelperAbstract::setDefaultRole('member');