我从 Symfony2 开始,我试图覆盖 FOSUserBundle 的 FOS\UserBundle\Form\Handler\RegistrationFormHandler。
我的代码是:
<?php
namespace Testing\CoreBundle\Form\Handler;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Form\Handler\RegistrationFormHandler as BaseHandler;
use Testing\CoreBundle\Entity\User as UserDetails;
class RegistrationFormHandler extends BaseHandler
{
protected function onSuccess(UserInterface $user, $confirmation)
{
// I need an instance of Entity Manager but I don't know where get it!
$em = $this->container->get('doctrine')->getEntityManager();
// or something like: $em = $this->getDoctrine()->getEntityManager
$userDetails = new UserDetails;
$em->persist($userDetails);
$user->setId($userDetails->getId());
parent::onSuccess($user, $confirmation);
}
}
所以,关键是我需要一个 Doctrine 实体管理器的实例,但在这种情况下我不知道在哪里/如何获得它!
任何想法?
提前致谢!