如果你需要为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());
}
如果你需要看到更多的代码,请让我知道,但希望这可以让你开始。
嗨。感谢您的回复。对不起,如果我的措辞不是最好的,但那是我有效的地方。 因此,在$ someOtherClass-> isAllowed需要获取该匹配路径(或父母)中当前页面的资源,以评估用户是否被允许访问该页面。 功能已经可以在面包屑视图助手的组合中找到,它可以从导航cfg中找到我的当前页面,菜单视图助手可以根据用户的角色和该页面的资源隐藏菜单中的某些页面。 我假设会有一种方法来实现这一点。 –