Draeli
Draeli

Reputation: 162

Symfony2 : addListener without using EventSubscriber class

I have a manager and inside a method. Inside this method, I want to add a listener connect to Doctrine and use this :

$dispatcher = $this->container->get("event_dispatcher");
$dispatcher->addListener(Events::onFlush, function (Event $event) {
    var_dump('test');die;
});

But in this case nothing append. Do you have a solution to accomplish this ? I read a lot of time documentation about listener but I don't understand why didn't work :/ (and I don't want to use EventSubscriber class)

Thank you

Upvotes: 0

Views: 77

Answers (1)

M. Foti
M. Foti

Reputation: 3182

Your code seems good, you have to use the doctrine event dispatcher and not the Symfony one.

$doctrineEventManager = $this->em->getEventManager();
$doctrineEventManager->addEventListener(Events::onFlush, New YourEventListenerClass()});;

Upvotes: 1

Related Questions