I have a problem with subscribing events for FOSUserBundle (I am using this tutorial).
Basically, I am trying to just redirect a user to specified route after login. I made a class, just like in the tutorial:
//src:src/AppBundle/EventsListener/LoginListener.php
namespace AppBundle\EventsListener;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\Event\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class LoginListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::SECURITY_IMPLICIT_LOGIN => 'onSecurityImplicitLogin',
);
}
public function onSecurityImplicitLogin(FormEvent $event)
{
return $this->redirectToRoute('profile');
}
}
And my services.yml looks like this:
services:
login_listener:
class: AppBundle\EventsListener\LoginListener
arguments: ['@router']
tags:
- { name: 'kernel.event_subscriber' }
But it still redirects me to the "\" route. Can somebody help me find what's wrong? Besides, is this really the only way to define routes in this bundle?
And, by the way, are there any resources/manuals besides this one, "official docs"? I've found this manual very unclear and rough.
Thank you for concern!