我正在使用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%確定如何去做這件事。