如果您需要匹配 ACL 的路由,请考虑执行以下操作:
/**
* Retrieve the route match
*
* @return string
*/
protected function getMatchRoute()
{
$router = $this->getServiceLocator()->get('router');
$request = $this->getServiceLocator()->get('request');
$this->routeMatch = $router->match($request)->getMatchedRouteName();
return $this->routeMatch;
}
然后在你的控制器中:
// note, $acl is just a class I wrote to extend class Zend\Permissions\Acl\Acl
// because I needed additional functionality
$acl = new \PATH_TO\Acl\Acl();
// checkAcl(), just however you plan on handling permissions
// $role is obviously just that, the role of the user, where ever
// you are setting that.
// the second param is from the method in the above code block which is the
// resource (page) you are wanting to check against
$access = $acl->checkAcl($role, $this->getMatchRoute());
// they don't have access so redirect them
if (!$access)
{
return $this->redirect()->toRoute('your_route', array());
}
如果您需要查看更多代码,请告诉我,但希望这可以帮助您入门。