我跟着這個教程登錄後重定向設置到最後一頁:http://www.reecefowell.com/2011/10/26/redirecting-on-loginlogout-in-symfony2-using-loginhandlers/登錄重定向服務處理錯誤參數
我services.yml
parameters:
assinatura_user_security.component.login_success_handler.class: Assinatura\UserBundle\Component\LoginSuccessHandler
services:
assinatura_user_security.component.login_success_handler:
class: %assinatura_user_security.component.login_success_handler.class%
arguments: [@service_container, @router, @security.context]
tags:
- { name: 'monolog.logger', channel: 'security' }
security.yml
form_login:
login_path: usuario_login
check_path: usuario_login_check
success_handler: assinatura_user_security.component.login_success_handler
我的課程:
<?php
namespace Assinatura\UserBundle\Component;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface
{
protected $router;
protected $security;
public function __construct(Router $router, SecurityContext $security)
{
$this->router = $router;
$this->security = $security;
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
$referer_url = $request->headers->get('referer');
$response = new RedirectResponse($referer_url);
return $response;
}
}
和錯誤:
Catchable Fatal Error: Argument 1 passed to Assinatura\UserBundle\Component\LoginSuccessHandler::__construct() must be an instance of Symfony\Component\Routing\Router, instance of appDevDebugProjectContainer given, called in /var/www/assinatura/app/cache/dev/appDevDebugProjectContainer.php on line 131 and defined in /var/www/assinatura/src/Assinatura/UserBundle/Component/LoginSuccessHandler.php line 18
我symfony的版本是2.2
我想重定向到同一頁面時沒有登錄