Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a global listener #778

Open
mirza99 opened this issue Aug 5, 2014 · 3 comments
Open

Set a global listener #778

mirza99 opened this issue Aug 5, 2014 · 3 comments

Comments

@mirza99
Copy link

mirza99 commented Aug 5, 2014

Hi, I have created a listener but the preUpdate() method is not called.

In the EditController the method saveObject() calls : $em->persist($Contact);

So, the prePersist should be called but, it isn't and even the post method aren't called

The config looks like this :

my.objectlistener:
        class: Acme\DemoBundle\Listener\ObjectListener
        arguments: [@service_container]
        tags:
            - { name: doctrine.event_listener, event: preUpdate }
            - { name: doctrine.event_listener, event: prePersist }

What should I do ?

@ioleo
Copy link
Member

ioleo commented Aug 5, 2014

Make sure your yaml config file is read by DI Extension class.

@mirza99
Copy link
Author

mirza99 commented Aug 5, 2014

I use the file app/config/config.yml the method onFlush is called but not the others...
The listener class is very simple I don't know if I should show it here, here is one method :

 public function preUpdate(\Doctrine\ORM\Event\PreUpdateEventArgs $args){
    var_dump('ok'); die;
}

@sescandell
Copy link
Member

Hi @mirza99

This sounds more like a configuration error because the Admingenerator doesn't handle anything about that.
Generated code is similar to this:

    protected function saveObject(\Acme\DemoBundle\Entity\Product $Product)
    {
        $em = $this->getDoctrine()->getManagerForClass('Acme\DemoBundle\Entity\Product');
        $em->persist($Product);
        $em->flush();
    }

So Doctrine listeners should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants