First register the service as a Doctrine event listener:
app/config.yml :
services: foo.listener: class: Vendor\FooBundle\BarClass tags: - { name: doctrine.event_listener, event: postPersist, method: onPostPersist }
Then, in your listener class, define the onPostPersist method (or what you called the method in config) that takes the Doctrine\ORM\Event\LifecycleEventArgs argument:
public function onPostPersist(LifecycleEventArgs $eventArgs) {
Note that you cannot pass an EntityManager instance to the listener class, because $ eventArgs contains a reference to it, and a CircularReferenceException is thrown.
Doctrine project documentation here . Symfony documentation here (deprecated but included for reference) /
source share