Search code examples
symfony1doctrinesymfony-1.4doctrine-1.2

Adding a Doctrine event listener to all tables in Symfony 1.4


Is there a quick way to add a Doctrine event listener to all tables in a Symfony 1.4 project?

I've tried adding this to the Doctrine_Manager in ProjectConfiguration::configureDoctrine() but this doesn't seem to get called. DQL callbacks are enabled, and regular behaviours seem to work - I just can't seem to attached my listener properly.

I'm extending the Doctrine_Record_Listened like so:

<?php class siteFilterListener extends Doctrine_Record_Listener { ... }

Solution

  • The best way to achieve (whatever you are trying to) is to create a behaviour which has a listener and add that behaviour to each of your doctrine table. Enable callbacks, and your listener will be called for the events you've overridden: insert, delete, postsave, postdql.

    I would suggest you use any behaviour plugin as your base, and start making changes. I have written 4 very simple behaviours, each with just 2 code files - that can be a good starting point for you.

    http://www.symfony-project.org/plugins/developer/prasad-gupte