我想创建一个应该在创建实体后发送电子邮件的监听器。
我正在使用Sonata Admin Bundle,而且我不太清楚哪个事件与创建实体相关联。
答案 0 :(得分:2)
您可以为Doctrine postFlush
事件注册事件监听器。
示例监听器:
class PostFlushExampleListener
{
public function postFlush(PostFlushEventArgs $args)
{
// ...
}
}
Symfony中的服务注册:
services:
my.listener:
class: PostFlushExampleListener
tags:
- { name: doctrine.event_listener, event: postFlush }
Symfony文档:http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html