Skip to content

Instantly share code, notes, and snippets.

@fabiopaiva
Created November 25, 2014 11:40
Show Gist options
  • Save fabiopaiva/a30b05cdb38b2ed6e4c9 to your computer and use it in GitHub Desktop.
Save fabiopaiva/a30b05cdb38b2ed6e4c9 to your computer and use it in GitHub Desktop.
BjyAuthorize + Navigation
<nav>
<?php echo $this->
navigation('navigation')
->menu()
->setUlClass('nav navbar-nav');
?>
</nav>
<?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')
),
)
)
)
);
<?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