tags:

views:

27

answers:

2

Hi, I am creating a custom magento module and cant decide the best place to store some config files i require with the module?

Anyone out there suggest the best place for this? Should it be in the root of the module or in with the helpers maybe?

Edit: Along the same lines as this question: is it acceptable to have a folder in the root of the namespace for the modules for includes that will be shared amongst the modules?

A: 

You could probably get away with this, but you're purposely avoiding Magento to do so. Inside a module, make a directory called etc and put an XML config file in it called config.xml. That file will be read and included in the Magento configuration, which means you won't have to try to escape the framework to grab your configuration data. Take a look at the existing files for some examples.

The other benefit to this approach is that the conversion from config XML files to user configuration options (in the admin panel) isn't too difficult (requires minor refactoring), so you can later change your configuration method with ease.

Hope that helps!

Thanks, Joe

Joseph Mastey
To your second question, Magento may not cause any errors, but it's probably not a good idea. Some module may come down the line later and expect those module directories to contain modules.
Joseph Mastey
Hi Joes thanks, all i reall need in these files are some arrays with data. Should this type of thing still go somewhere in the config.xml
David
Yes, if you can, you should put them into the config files. As stated above, this will make sure that any new code changes to Magento later on won't have negative repercussions for your module, and will allow you to manipulate those values in the framework itself.
Joseph Mastey
Probably a better approach is what Alan alluded to above (using the Admin System Config). That will store your arrays in the database in the `core_config_data` table and provide web-based access for administrators to edit them if required with needing FTP/SSH access.
Jonathan Day
I agree in some cases, namely the actual data being stored for configuration. Anything that could change between sites should be configurable via the admin panel. There are, however, other options that don't need to be exposed to the administrator, and cluttering the config panel (even further) is not a good idea. Hence my above suggestion.
Joseph Mastey
+1  A: 

If these files are for configuration, they belong in etc. Think of the etc folder the same way you would a unix/linux/bsd system's etc folder. It's where you put configuration information. Convention is that you should use an XML file to hold your config data, and then load it with

Mage::getConfig()->loadModulesConfiguration('your-xml-name-here.xml')

When you use the loadModulesConfiguration method to load your configuration values, Magento combines XML files for ALL modules in the system into one big tree. This allows other modules you'll write (or others would write) to share the configuration information.

You don't need to do this, but etc is definitely the defined place for any configuration files you want to include with your module. Also, whatever method you're choosing, I'd pick a unique file name (packagename_modulename.xml, packagename_modulename.inc, etc.) to ensure against the slim possibility that someone at Magento might pick your name to use in a future version.

Along the same lines as this question: is it acceptable to have a folder in the root of the namespace for the modules for includes that will be shared amongst the modules?

No, that would not be acceptable. If you want a shared configuration, use the method I mentioned above. If modules need to share other information with each other, they should either do so directly (one module instantiates another module's model) or you should define a central "broker" module that handles all inter-module communication. If you're interested more in the topic, I'd recommend the first few chapters of Meyer's Object-oriented Software Construction. If you can get past the whole "how to implement low level data structures" aspected of old programming books, its a great introduction to what CS people when they say "module".

(it's also worth mentioning that if there are simple configuration values, learning how to use the Magento System Config Admin section is worth it.)

Alan Storm