Конечно, я работаю над перенаправлением после регистрации в FOSUserBundle и eventListener,
RegistrationConfirmListener.php
<?php
namespace BISSAP\UserBundle\EventListener;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\UserEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class RegistrationConfirmListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_SUCCESS => 'onRegistrationSuccess'
);
}
public function onRegistrationSuccess(GetResponseUserEvent $event)
{
$url = $this->router->generate('bissap_bodyconcept_homepage');
$event->setResponse(new RedirectResponse($url));
}
}
Итак, я получаю:
Catchable Fatal Error: Argument 1 passed to BISSAP\UserBundle\EventListener\RegistrationConfirmListener::onRegistrationSuccess() must be an instance of BISSAP\UserBundle\EventListener\GetResponseUserEvent, instance of FOS\UserBundle\Event\FormEvent given
Я пытаюсь двигаться
public function onRegistrationSuccess(GetResponseUserEvent $event)
от
public function onRegistrationSuccess(FOS\UserBundle\Event\FormEvent $event)
Но я получаю:
Catchable Fatal Error: Argument 1 passed to BISSAP\UserBundle\EventListener\RegistrationConfirmListener::onRegistrationSuccess() must be an instance of BISSAP\UserBundle\EventListener\FOS\UserBundle\Event\FormEvent, instance of FOS\UserBundle\Event\FormEvent given
И когда я заменяю REGISTRATION_SUCCESS
от REGISTRATION_CONFIRM
в RegistrationConfirmListener.php:
namespace BISSAP\UserBundle\EventListener;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\UserEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class RegistrationConfirmListener implements EventSubscriberInterface
{
private $router;
public function __construct(UrlGeneratorInterface $router)
{
$this->router = $router;
}
/**
* {@inheritDoc}
*/
public static function getSubscribedEvents()
{
return array(
FOSUserEvents::REGISTRATION_CONFIRM => 'onRegistrationConfirm'
);
}
public function onRegistrationConfirm(GetResponseUserEvent $event)
{
$url = $this->router->generate('bissap_bodyconcept_homepage');
$event->setResponse(new RedirectResponse($url));
}
}
Я не получаю ошибки, но перенаправление не работает.
Информация: я использую оригинальный RegistrationController.php от FOSUserBundle
Задача ещё не решена.
Других решений пока нет …