2014-04-01 99 views
0

我正在使用zfc-user和ZfcRbac的ZendFramework2进行授权和访问控制。我已经设置了一切与数据库管理角色一起工作。现在,当用户浏览到一个未经授权的网页,我收到错误页面You are not authorized to access this resource这是由ZfcRbac如何将未经授权的用户重定向到403页

抛出其实我在zfc-rbac.global.php已配置重定向到403页。我的设置如下。

ZfcRbac\Exception\UnauthorizedException 

-

'unauthorized_strategy' => [ 
    'template' => 'error/403' 
], 

如何将用户发送到403页?

编辑

正确的答案是将UnauthorizedStrategy附着在onBootstrap

$t = $e->getTarget(); 
$t->getEventManager()->attach(
    $t->getServiceManager()->get('\ZfcRbac\View\Strategy\UnauthorizedStrategy') 
); 

回答

2

ZfcRbac每默认情况下不会做任何事情,但抛出异常。 ZfcRbac的强大之处在于它的许多可定制功能。您应该查看的那个可以在Documentation-Section "Strategies"下找到。

总之

  • 注册你的模块重定向策略onBootstrap
  • 如果需要的话,改变重定向策略配置
+0

确定。认为进展顺利。我用正确的事件附件更新了我的问题。 – BlueBird

+0

403页面显示为任何内容。 403错误时如何显示整个不同的布局? – cwhisperer

相关问题