Aplication scope variables in Zend Framework 2?

993 views Asked by At

I want have an store of variables visibles for all application (application space). I want it because I need access to $locale variable from all views for translate my multilanguage web.

I know in ZF1 there was a ZEND_REGISTRY class, but it has been removed.

How I can do the same feature in ZF2? Does it serve DI class (dependency Injector) for done this function?

I have listened also anything about create service factories for classes that have dependencies, and to use the ServiceManager then to manage all dependencies.

I need an example because I've never worked with DI, factories nor ServiceManager.

1

There are 1 answers

2
vascowhite On

Variables visible to your whole application are no better than globals and, in this case, you don't need to use them.

ZF2 has the I18n class as one of the core classes.

If you download and set up the skeleton application you will find an example of translation in ZF2 already up and running.

There is a nice explanation here.