2013-04-08 12 views

答えて

37

それはリセット加入者を作成することによって行うことができます。

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)); 
    } 
} 

そしてkernel.event_subscriberタグと、それをサービスとして登録する:あなたはFOSユーザープロファイルビューを使用していない場合は

# 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

注:このソリューションでは、FOS Userbundleのマスターバージョンを使用する必要があります。 リセットコントローラを拡張し、getRedirectionUrl()メソッドを変更することで、類似の結果を得ることができます。 –

19

醜い単純な方法があります:

app/config/routing.yml

fos_user_profile_show: 
    path: /yourpath 
+2

絶対パスよりも良い名前の 'fos_user_profile_show'という名前で、あなた自身のコントローラでルートを宣言することもできます。 –

+2

@LouTerrailloune上記のルーティング設定に絶対URLはありません。それはそれのように見えるかもしれないが、それはaint –

関連する問題