Finaly, i found a solution.
In First, i try to render to another page from registrationController. and it's not totaly wrong if i don't data showed in this page.
one of the contributors of FOSUserBundle reply on a question of this render and he said and i quote: "The login is not handled by FOSUserBundle at all, but by the Symfony security component. this bundle is about providing user management only"
So i search for another logic.
I create a listener. and i named it in the config.yml (projectname/SourcesFiles/app/config/config.yml)
services:
fos_user.doctrine_registry:
alias: doctrine
sdz_user.registration_complet:
class: Acme\CovoiturageBundle\Services\RegistrationConfirmListener
arguments: [@router]
tags:
- { name: kernel.event_subscriber }
so the listener will be listen to the event subscriber from the symfony core.
After that, add a folder in your bundle and add a php class named RegistrationConfirmListener:
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(\FOS\UserBundle\Event\FormEvent $event) {
$url = $this->router->generate('index');
$event->setResponse(new RedirectResponse($url));
}
}
you will need the uses from FOSUserBundle:
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
be careful, if you don't put the namespace on the top, the symfony don't recognize your class.
namespace Acme\CovoiturageBundle\Services
did you see the "REGISTRATION_SUCCESS"? i take this from the registrationController from the function registraionAction:
$dispatcher->dispatch(FOSUserEvents::**REGISTRATION_COMPLETED**, new FilterUserResponseEvent($user, $request, $response));
so, now try to test your listener if he is working or not by run this command :
php app/console container:debug | app_user.registration_complet
and you will get this message on the console :
[container] Information for service sdz_user.registration_complet
Service Id sdz_user.registration_complet
Class Acme\CovoiturageBundle\Services\RegistrationConfirmListener
Tags
- kernel.event_subscriber ()
Scope container
Public yes
Synthetic no
Lazy no
Synchronized no
Abstract no
Done.
I don't made a solution for the login. this solution for registration. I think it will be the same logic.