问题
I'm a beginer zend framework programmer. I did use ZfcUser for authentification and Bjyauthorize for authorization. I have to type of users : normal users and administrator . So what i want to do is to route the user to page A and admin to page B after authentification . In the Zfcuser configuation file there not this possibility we have just this line
'logout_redirect_route' => 'zfcuser/login',
how can do specify a diffrent route for my differents users?
回答1:
To me your problem has nothing to do with ZfcUser or BjyAuthorize: Just let the user and the admin go inside your controller and there you can dispatch them depending on the user role.
return $this->forward()->dispatch('MyModule\Controller\Index', array('action'=>'PageB'));
回答2:
Suppose you have an 'admin' role in bjyauthorize that you want to redirect to another route.
In your loginAction replace the code:
if ($this->zfcUserAuthentication()->getAuthService()->hasIdentity()) {
return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
}
with this code:
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');
}
}
来源:https://stackoverflow.com/questions/16674060/zend-framework2-using-zfcuser-bjyauthorize-routing