[FLOW3-general] Accessing resources from classes
Manuel Strausz
tminus at bitmap.co.at
Tue Dec 1 17:11:33 CET 2009
Zachary Davis, Cast Iron Coding LLC schrieb:
> Hi all,
>
> Are there any best practices in place for accessing files in a packages
> resources directory? I'm trying to come up with a good way to pull error
> messages and flash messages out of the code and into an external
> document. I've been considering storing them in XML somewhere in
> Resources/Private and writing a simple service that can be used by
> controllers and view helpers to retrieve the text, but I'm not sure what
> the best way is to access files in Resources from within a class.
>
> Or, perhaps settings.yaml is a better place to store this sort of thing?
>
> best,
> Zach
Hey Zach,
I think this really depends on your needs. Will you have a huge amount
of distinct error messages, or will they be relatively generic and few
in number?
If they are few, I would put them in the respective Settings.yaml, which
can be accessed easily in every action controller.
If they are getting more in number, or you want to keep it generic, you
could make e.g. an injectErrorMessageFetcher method (or any other name
you choose) in each controller, which would let the object builder
inject an error message fetcher of your choosing. The respective
implementation of that fetcher would be up to you, so you could store it
in xml, a database, or any other datasource you write the code for :)
Hmm thinking about it this does sound like a rather general problem, so
I could see this becoming a framework component of its own. If the
powers in charge here approve of it, I could write an interface and a
few generic implementations.
If there is already a component like that and I managed to overlook it,
please excuse my ignorance ;)
Hope this helps
regards,
Manuel
More information about the FLOW3-general
mailing list