So let’s say you’ve been tinkering about with the example given on the Symfony 2 manual page for configuring a Doctrine Event Subscriber.
All is good.
Maybe you’ve been through and configured it just like the example, added a subscriber, re-run your fixtures, and everything is tickedyboo.
But then you make a few changes to the subscriber implementation. Maybe it should do something a little differently, and you want to re-save the entity, and get the new implementation to take effect.
Only, it won’t.
You tinker about some more, and everything looks sane. But for some reason, when you go to your form, change nothing, and click the Submit button, the listener just doesn’t seem to take effect.
See, there’s a big ol’ list of lifecycle events that you can hook into, and do funky things with.
But each one has a weird, technical description that doesn’t quite seem to explain what it does in a way that’s easy to comprehend.
If you followed the Symfony documentation example, you might think a
postPersist would be triggered whenever you Submit the form. After all, if you stick some debugs in your code, you can see the entity is persisted and the unit of work is flushed.
But yet, your listener doesn’t fire.
Try changing the data in your form, though, and suddenly the listener is triggered.
I’m 100% sure this isn’t a bug. It’s a misunderstanding.
But if you’ve been sat tearing your hair out as to why this damn thing just won’t do your bidding for the last 30 minutes, the only sane solution is to blog about it, and move on.
Hopefully this will save you a headache or two.