php - Grant ACL permission by URLs in Zend Framework 2 -
i follow tutorial: http://ivangospodinow.com/zend-framework-2-acl-setup-in-5-minutes-tutorial/ but, want grant permission custom urls, had changes in code.
in module.acl.roles.php
return array( 'guest'=> array( '/home.html', '/login.html', '/register.html' ), 'admin'=> array( '/user/add.html', '/user/edit.html', '/user/list.html', ), );
in module.config.php
return array( 'router' => array( 'routes' => array( '/home.html' => array( 'type' => 'zend\mvc\router\http\literal', 'options' => array( 'route' => '/', 'defaults' => array( 'controller' => 'application\controller\index', 'action' => 'index', ), ), ), '/user/add.html' => array( 'type' => 'zend\mvc\router\http\regex', 'options' => array( 'regex' => '/user/add.html', 'defaults' => array( 'controller' => 'application\controller\user', 'action' => 'add', 'format' => 'html', ), 'spec' => '/user/add.%format%', ), ), ... ), ), );
but received error: route name "" not found
. please give me advices , solutions grant permission urls
thank you!
i really recommend bjyauthorize module (https://packagist.org/packages/bjyoungblood/bjy-authorize).
but if want yourselft need add listener \zend\mvc\mvcevent::event_route
.
you can attach listener with
$events->attach(mvcevent::event_route, array($this, 'myonroute'), -1000);
and in myonroute method can handle route
public function myonroute(mvcevent $event) { $match = $event->getroutematch(); $routename = $match->getmatchedroutename(); // stuff here (compare config or whatever) }
Comments
Post a Comment