我正在尝试在我的 symfony2 应用程序中登录后实现重定向,以便在我的用户是否具有一个属性时进行重定向。我在我的项目的 Handler 文件夹中创建了类 AuthenticationSuccessHandler.php :
命名空间 Me\MyBundle\Handler;
使用 Symfony\Component\Security\Http\HttpUtils;
使用 Symfony\Component\HttpFoundation\RedirectResponse;
使用 Symfony\Component\HttpFoundation\Request;
使用 Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
使用 Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
类 AuthenticationSuccessHandler 扩展 DefaultAuthenticationSuccessHandler {
公共函数__construct(HttpUtils $httpUtils,数组$options){
父::__construct($httpUtils, $options);
}
公共函数 onAuthenticationSuccess( 请求 $request, TokenInterface $token ) {
$user = $token->getUser();
if($user->getProfile()!=1){
$url = 'fos_user_profile_edit';
}别的{
$url = '我的路线';
}
return new RedirectResponse($this->router->generate($url));
}
}
但是当我登录时,我得到一个错误:
注意:未定义的属性:/var/www/MyBundle/src/Me/MyBundle/Handler/AuthenticationSuccessHandler.php 第 28 行中的 Me\MyBundle\Handler\AuthenticationSuccessHandler::$router
错误发生在“return new RedirectResponse($this->router->generate($url));”中
我也有我的服务:
my_auth_success_handler:
类:我\MyBundle\Handler\AuthenticationSuccessHandler
公开:假
参数:[@security.http_utils,[]]
和 security.yml 中的成功处理程序:
fos_facebook:
成功处理程序:my_auth_success_handler
有任何想法吗?非常感谢。