how to add my xml config files to zend

thanks for reading, I'm new to zend and I have config files for my module in xml format, I don't want to use xml parser to load my config file every time I need my configurations. how can I add my directory to zend framework to make the files auto loaded and how can I get data from them. my config file in this directory: DirToZend/module/Application/src/Application/config/config.xml

any help will be appreciated

update: maybe my question is not clear. I don't want to configure the module it self, the xml file is for my use in models. I load it using xml reader, but this means I read the file from hard disk in every method of my model. I want my custom xml file be auto loaded so I don't have to read it from hard disk every time I need some configuration from it AND how can I invoke my configurations from it,

Answers


Regarding the autoloading - you can use something like this:

'module_listener_options' => array(
    'config_glob_paths' => array(
        'config/autoload/{,*.}{global,local}.php',
    ),
);

See http://framework.zend.com/manual/2.2/en/tutorials/config.advanced.html for general information about ZF2 config.

Additionally you need to configure the config reader as well. Have a look at http://samsonasik.wordpress.com/2012/10/06/zend-framework-2-setting-up-module-config-using-xml-file/ and http://burnhamup.com/blog/2013/06/using-ini-configuration-files-for-zend-framework-2/ for more information.

EDIT:

Please have a look at those blog entries, as well as http://framework.zend.com/manual/2.0/en/modules/zend.config.reader.html - you can incorporate those functionalities for any arbitrary XML config, it is not limited to Zend Framework module configuration.

If you want to read out a directory structure - e.g. for importing multiple config files - check http://www.php.net/manual/de/function.opendir.php

EDIT:

Think about how PHP code is run in general and how a request life-cycle looks like in a typical web application (I assume that you're working on a request oriented web application here and we are not talking about e.g. a single-run script or permanently running service):

A user visits your page and requests e.g. a specific content - your code fulfills this request by giving the respective response by showing the content - a very simple description of such a life-cycle. As soon as the user opens another content a new cycle begins and so on.

So if all your content is e.g. stored in an XML file you need to open, read and parse this XML file on every request. Therefore in first place you have no option to avoid this(*) or where you can read the contents out of the memory by magic ("without providing a path") but instead need to read it from file system in every cycle. Only within such a cycle you can store the results of your read and parse operation in a variable (in the memory) so that any of your functions (or e.g. any of your models in terms of MVC) can access and work with it.

(*) Though sure there are many strategies to overcome this situation where such operations are so heavy that you can not perform them on every single request - this is called caching in general and NOT auto-loading.

As your question is formulated so vague and you did not even provide any code example nor any description of your attempts to solve this problem by your own I'll stop at this point.

With my answer in mind try to make yourself clear what exactly you want to do - try to find out by yourself how you can achieve your goals and work it out. If you then have concrete implementation questions you can not solve by yourself or can not solve by searching stackoverflow or other resources come back and ask a new question while providing code, describing your attempts and formulating exactly.

Or maybe just google "ZF2 Zend Registry, Service Manager, Dependency Injection" to learn how you can exchange data between your models.


Need Your Help

Capistrano 3 Permission Denied

ruby-on-rails ruby capistrano capistrano3

I'm converting an app from capistrano version 2 to version 3 and now i'm getting this error:

Compiler attribute stuck on a function type - is there a workaround for this clang-cl bug?

c++ templates visual-studio-2015 calling-convention clang-cl

When using the C++ LLVM-vs2014 configuration in Visual Studio 2015, this static assert fails. The assert does not fail in clang++, gcc, or even Visual C++. The thiscall attribute is stuck on the fu...