如果你需要爲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中找到我的當前頁面,菜單視圖助手可以根據用戶的角色和該頁面的資源隱藏菜單中的某些頁面。 我假設會有一種方法來實現這一點。 –