我正在使用ZfcRbac并需要添加自定义重定向策略。我已阅读这里的文档re-direct strategy documents,但我不是100%确定如何实施替代stratergy我用例:ZF2-使用zfc-rbac进行自定义路由重定向
当用户试图在管理方面我目前重定向到管理员进入路径登录页面,如果他们还没有登录。
当客户登录到他们的帐户页面时,我需要将他们重定向到客户登录页面。目前他们被重定向到管理员登录页面。
我Module.php文件有这个::
public function onBootstrap(EventInterface $e)
{
$t = $e->getTarget();
$t->getEventManager()->attach(
$t->getServiceManager()->get('ZfcRbac\View\Strategy\RedirectStrategy')
);
}
我全球有这种::
<?php
return [
'zfc_rbac' => [
'protection_policy' => \ZfcRbac\Guard\GuardInterface::POLICY_ALLOW,
'guards' => [
'ZfcRbac\Guard\RouteGuard' => [
//ADMIN ACCOUNT GUARDS
'user' => ['admin-master'],
'user/login' => ['guest'],
'user/logout' => ['admin-master', 'merchant-worker', 'guest'],
'user/register' => ['admin-master', 'merchant-admin', 'guest'],
'user/change-password' => ['admin-master', 'merchant-worker'],
'user/forgot-password' => ['guest'],
//CUSTOMER ACCOUNT GUARDS
'customer' => ['customer'],
]
],
'identity_provider' => \RoleBasedUser\Service\AuthenticationService::class,
'role_provider' => [
'ZfcRbac\Role\ObjectRepositoryRoleProvider' => [
'object_manager' => 'doctrine.entitymanager.orm_default',
'class_name' => 'RoleBasedUser\Entity\HierarchicalRole',
'role_name_property' => 'name'
]
],
'redirect_strategy' => [
'redirect_when_connected' => true,
'redirect_to_route_connected' => 'home',
'redirect_to_route_disconnected' => 'user/login',
'append_previous_uri' => true,
'previous_uri_query_key' => 'redirectTo'
],
]
];
为了使这项工作,我相信我需要写一个自定义stratergy但是,我不是100%确定如何去做这件事。