Created
November 25, 2014 11:40
-
-
Save fabiopaiva/a30b05cdb38b2ed6e4c9 to your computer and use it in GitHub Desktop.
BjyAuthorize + Navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<nav> | |
<?php echo $this-> | |
navigation('navigation') | |
->menu() | |
->setUlClass('nav navbar-nav'); | |
?> | |
</nav> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return array( | |
'navigation' => array( | |
'default' => array( | |
array( | |
'label' => 'HOME', | |
'route' => 'home', | |
// Aqui eu configuro como quero bloquear, poder ser pelo controller, router ou criar um novo resource | |
// No caso vou usar controller no Guard | |
'resource' => 'controller/Application\Controller\Index:index' | |
//'resource' => 'router/home' | |
//'resource' => 'novoResource' | |
), | |
) | |
) | |
'bjyauthorize' => array( | |
'guards' => array( | |
'BjyAuthorize\Guard\Controller' => array( | |
array( | |
'controller' => 'Application\Controller\Index', | |
'action' => array('index','outraAction'), | |
'roles' => array('Gerente','Administrador') | |
), | |
) | |
) | |
) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application; | |
use Zend\Mvc\MvcEvent; | |
class Module{ | |
public function onBootstrap(MvcEvent $e) { | |
$sm = $e->getApplication()->getServiceManager(); | |
// Add ACL information to the Navigation view helper | |
$authorize = $sm->get('BjyAuthorizeServiceAuthorize'); | |
$acl = $authorize->getAcl(); | |
$role = $authorize->getIdentity(); | |
\Zend\View\Helper\Navigation::setDefaultAcl($acl); | |
\Zend\View\Helper\Navigation::setDefaultRole($role); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment