2012-09-03 53 views

回答

1

如果您可以使用dev-master(2.0.*@dev),那麼您可以使用FOSUserBundle中的新控制器事件。有關詳細信息,請參閱github上的文檔:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/controller_events.md

以下是確認事件的一個示例。不要忘記在上面的鏈接中提到定義服務。

<?php 

namespace Acme\UserBundle\Security\Listener; 
use FOS\UserBundle\Event\GetResponseUserEvent; 
use FOS\UserBundle\FOSUserEvents; 
use Symfony\Component\EventDispatcher\EventSubscriberInterface; 

class RegistrationListener implements EventSubscriberInterface 
{ 
    public function __construct(/** inject services you need **/) 
    { 
     // assign services to private fields 
    } 

    public static function getSubscribedEvents() 
    { 
     return array(FOSUserEvents::REGISTRATION_CONFIRM => 'onRegistrationConfirm',); 
    } 

    /** 
    * GetResponseUserEvent gives you access to the user object 
    **/ 
    public function onRegistrationConfirm(GetResponseUserEvent $event) 
    { 
     // do your stuff 
    } 
} 
相關問題