user1929946
user1929946

Reputation: 2503

Symfony 1.4, global objects: where to put?

I need to store a "global" object in Symfony 1.4 system, so not a usual class into the /lib directory. This could even be a full static, or singleton thing - but nowadays everybody say "use dependency injection!". Buy the way, this object must be exists in only one instance, not less, not more, and accessible in all controllers (not in views) I think it should be created in the chain filter. And then?

Upvotes: 0

Views: 195

Answers (1)

Michal Trojanowski
Michal Trojanowski

Reputation: 12322

You can either keep the object inside the sfContext or, if you want to have it a separate object, implement a static method ::getInstance(), which will return the instance of the object or initialise it (if the instance does not exist). This way you don't even have to initialise the object in the filter chain (unless you need to pass some parameters to the constructor).

Upvotes: 1

Related Questions