2013-05-21 48 views
0

我是一个beginer zend框架程序员。我确实使用ZfcUser进行身份验证,并使用Bjyauthorize进行授权。我必须输入用户类型:普通用户和管理员。所以我想要做的是将用户路由到页面A和管理员页面B后认证。 在Zfcuser configuation文件中有没有这种可能性,我们刚才这条线Zend Framework2使用Zfcuser&Bjyauthorize路由

'logout_redirect_route' => 'zfcuser/login', 

怎么办指定我型动物用户指出错误路线?

回答

0

对我来说,你的问题与ZfcUser或BjyAuthorize无关:只要让用户和管理员进入你的控制器,你就可以根据用户角色发送它们。

return $this->forward()->dispatch('MyModule\Controller\Index', array('action'=>'PageB')); 
0

假设您在bjyauthorize中有'管理员'角色,您希望重定向到另一个路由。与此代码

if ($this->zfcUserAuthentication()->getAuthService()->hasIdentity()) { 
     return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute()); 
    } 

在你的LoginAction替换代码

if ($this->zfcUserAuthentication()->getAuthService()->hasIdentity()) { 
     $roles = $this->serviceLocator->get('BjyAuthorize\Provider\Identity\ProviderInterface')->getIdentityRoles(); 
     if (in_array('admin',$roles)) 
     { 
      return $this->redirect()->toRoute('admin_route'); 
     } else { 
      return $this->redirect()->toRoute('user_route'); 
     } 
    }