2013-04-08 9 views

Odpowiedz

37

Można to zrobić poprzez stworzenie resetowanie subskrybenta:

namespace Acme\UserBundle\EventListener; 

use FOS\UserBundle\FOSUserEvents; 
use FOS\UserBundle\Event\FormEvent; 
use Symfony\Component\EventDispatcher\EventSubscriberInterface; 
use Symfony\Component\HttpFoundation\RedirectResponse; 
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 

/** 
* Listener responsible to change the redirection at the end of the password resetting 
*/ 
class PasswordResettingListener implements EventSubscriberInterface { 
    private $router; 

    public function __construct(UrlGeneratorInterface $router) { 
     $this->router = $router; 
    } 

    public static function getSubscribedEvents() { 
     return [ 
      FOSUserEvents::RESETTING_RESET_SUCCESS => 'onPasswordResettingSuccess', 
     ]; 
    } 

    public function onPasswordResettingSuccess(FormEvent $event) { 
     $url = $this->router->generate('homepage'); 
     $event->setResponse(new RedirectResponse($url)); 
    } 
} 

A potem zarejestrowanie go jako usługa z kernel.event_subscriber tagu:

# src/Acme/UserBundle/Resources/config/services.yml 
services: 
    acme_user.password_resetting: 
     class: Acme\UserBundle\EventListener\PasswordResettingListener 
     arguments: [ @router ] 
     tags: 
      - { name: kernel.event_subscriber } 
+4

Uwaga: to rozwiązanie wymaga użycia wersji głównej dla FOS Userbundle. Można osiągnąć podobny wynik przez rozszerzenie kontrolera resetowania i zmianę metody getRedirectionUrl(). –

19

W przypadku, gdy nie jest używany widok profilu użytkownika FOS jest brzydki, ale prosty sposób:

Dodaj swój app/config/routing.yml:

fos_user_profile_show: 
    path: /yourpath 
+2

Możesz również zadeklarować trasę we własnym kontrolerze o nazwie 'fos_user_profile_show', lepszym niż bezwzględny URL. –

+2

@LouTerrailloune nie ma bezwzględnego adresu URL w powyższej konfiguracji routingu. To może wyglądać, ale to nie jest –

Powiązane problemy