创建实体后发送邮件Symfony2 Sonata Admin Bundle

时间:2016-02-23 10:45:50

标签: symfony events sonata

我想创建一个应该在创建实体后发送电子邮件的监听器。

我正在使用Sonata Admin Bundle,而且我不太清楚哪个事件与创建实体相关联。

1 个答案:

答案 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

学说文档:http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/events.html#listening-and-subscribing-to-lifecycle-events