【发布时间】:2015-01-14 11:47:57
【问题描述】:
我正在考虑实施 ACL 的最佳方式。所以 - 我需要保护某些路线。有些路线仅供用户访问,有些是访客访问,有些是管理员访问。
似乎最好的方法是在路由配置中添加一个 $role 变量。因此,我将附加到路由后事件,获取 routeMatch,然后我会查看此用户是否可以输入此路由。
我该怎么做?我可以像这样简单地注入额外的变量吗:
'router' => array(
'routes' => array(
'route1' => array(
'type' => 'Zend\Mvc\Router\Http\Regex',
'options' => array(
'regex' => '/some/route/1',
'defaults' => array(
'controller' => 'Subscriber\Controller\View',
'action' => 'route1',
'role' => 'user', //extra
),
'spec' => '/some/route/1',
),
),
'route2' => array(
'type' => 'Zend\Mvc\Router\Http\Regex',
'options' => array(
'regex' => '/some/route/2',
'defaults' => array(
'controller' => 'Subscriber\Controller\View',
'action' => 'route2',
'role' => 'guest', //extra
),
'spec' => '/some/route/2',
),
),
//other routes....
),
),
【问题讨论】:
标签: php zend-framework zend-framework2 acl