Hi ! What I always see is not to use sfContext directly in model, but :
sfProjectConfiguration::getActive()->getEventDispatcher()->notify(new sfEvent($this, 'foo.bar')); ( as you already said ) An other solution is to inject your dispatcher like this : //in your form class: public function setEventDispatcher(sfEventDispatcher $dispatcher) { $this->eventDispatcher = $dispatcher; } // then in your action (or whatever else ): $form = new myForm; $form->setEventDispatcher($this->dispatcher); But if it doesn't work with the first solution, it surely won't with this one. Hope it helps ! Florian. On Oct 5, 10:37 am, rich_81 <rich.s...@gmail.com> wrote: > Hi all, > > Hope you can help with this - it's got me stumped! > > Using Symfony 1.2.9, I have a situation where I'm raising an event via > the dispatcher, during the saving of a form - I have multiple embedded > forms which need to raise the event upon each individual form's > saving. I'm seeing this currently in a unit test for the form. > > I have added my event method in the project configuration as normal, > using: > > $this->dispatcher->connect("transaction.add", array > ("TransactionManager", "sendAllocationEmail")); > > and I'm then raising the event in my form class using: > > sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent > (null, "transaction.add", array())); > > (I've tried sfProjectConfiguration::getActive()->getEventDispatcher() > as well) > > The problem is that the event is getting raised 4 times, no matter > where in the form class I use this. I've tried moving it to the > configure() method, I've tried removing all the embedded forms, and > still my method is being called 4 times. > > The strange thing is, if I do: > > sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent > (null, "application.log", array("About to raise my event"))); > sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent > (null, "transaction.add", array())); > sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent > (null, "application.log", array("Raised my event"))); > > in my log, I get the following: > > Oct 05 09:29:35 symfony [info] {main} About to raise my event > Oct 05 09:29:35 symfony [info] {main} In my event's method > Oct 05 09:29:35 symfony [info] {main} In my event's method > Oct 05 09:29:35 symfony [info] {main} In my event's method > Oct 05 09:29:35 symfony [info] {main} In my event's method > Oct 05 09:29:35 symfony [info] {main} Raised my event > > The only code I have in my event handler at the moment is the > application.log call. > > Has anybody else come across this at all? Is there a better way to > retrieve the event dispatcher in the form, apart from upgrading to > Symfony 1.3? :-) > > Thanks in advance, > > Rich. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---