Hi Joe,

On Thu, Jul 2, 2009 at 11:23 PM, JoeZ<[email protected]> wrote:
> So I came out with this (I'm not yet sure it will work. I can tell you
> it compiles).

You should never let your model rely on the context or on the
configuration. Further more, you should try to avoid calling
Singletons in the model, because your model will become very
unflexible and erroneous then. I recently wrote a blog post about
exactly this topic, if you are interested:
http://webmozarts.com/2009/07/01/why-sfcontextgetinstance-is-bad/

If I was you, I would just use a setter like ->setEventDispatcher() to
store the dispatcher in the object. When you try to fire the event,
you check whether the dispatcher has been set. If it does not exist,
you either

1. Throw an exception because the event MUST be fired, or
2. Don't fire the event

Of course, you will then have to call ->setEventDispatcher() manually,
but that'll result in a much better application design than
"magically" accessing any objects from inside.

FYI, you should not use sfContext::getInstance() in the action either.
The action does already have a reference to the context:

public executeWhatever()
{
  $myObject = new myObject();
  $myObject->setEventDispatcher($this->context->getEventDispatcher());
}


Bernhard

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to