我正在尝试在提交个人资料表单时捕获任何Doctrine事件。我的活动如下:
testevent:
class: AppBundle\Event\TestListener
arguments: ['@service_container']
tags:
- { name: doctrine.event_subscriber }
- { name: doctrine.event_listener, event: prePersist, method: prePersist, connection: default }
我现在的事件,应该在转储当前实体时登录并退出应用程序:
class TestListener implements EventSubscriber
{
private $container;
public function __construct(\Symfony\Component\DependencyInjection\Container $container)
{
$this->container = $container;
}
public function prePersist(\Doctrine\ORM\Event\LifecycleEventArgs $args){
$entity = $args->getEntity();
$this->container->get('logger')->info('asdasd');
echo '<pre>';
\Doctrine\Common\Util\Debug::dump($entity); exit;
echo '</pre>';
}
public function getSubscribedEvents()
{
return array(
'onPrePersist'
);
}
}
我试过postPersist,preFlush,postFlush,没有人被抛出。但是,它们被我所制作的其他形式所抛弃,所以它必须与FOSUserBundle一起使用,也许?
看着控制器,它调用
$userManager->updateUser($user);
其中
public function updateUser(UserInterface $user, $andFlush = true)
{
$this->updateCanonicalFields($user);
$this->updatePassword($user);
$this->objectManager->persist($user);
if ($andFlush) {
$this->objectManager->flush();
}
}
对象管理器在包中声明如下:
<service id="fos_user.object_manager" class="Doctrine\Common\Persistence\ObjectManager" public="false">
<argument>%fos_user.model_manager_name%</argument>
</service>
这位经理是不是在调用Doctrine事件?我怎么能打电话给他们?