我需要注册我的实体监听器吗?我把它放在项目的什么地方?

Do I need to register my Entity Listener? Where do I put it in the project?

我正在尝试为我的实体创建实体侦听器,如

中所述

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#entity-listeners

我在 Symfony 文档中找到的参考文献是

http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html#creating-the-listener-class

其中有一条关于实体侦听器的注释。

如果我将我的 FooListener 放在与 Foo 实体相同的文件夹中(在本例中为 AppBundle\Entity)并进行注释 @EventListener,则侦听器会工作。但我不想将侦听器留在 Entity 文件夹中,如果不需要,我也不想通过将侦听器注册为服务来创建额外的配置。这里的最佳做法是什么?

您可以尝试使用 FooListener 的完整路径 f.e。 @ORM\EntityListeners({"AppBundle\EventListener\FooListener"})