On 2 Dec 2007, at 18:33, robert mena wrote:

Hi,

I've adopted ZF as the framework that I am rewriting my modules. One of the things I'd like to do is have a better way of changing / defining some of my modules' behaviour.

I am considering using Zend_Config (not sure if .ini o .xml) and have development, stagging and production config files. When the bootstrap is called I find out which enviroment I am using and in my __construct I load the appropriate config file.


Zend_Config supports the concept of inheritance within the config file. You can also use Zend_Config::merge() to merge multiple config objects into one if that suits you better.


I currently use a single config.ini file that is structured something like this:

[general]
module1name.setting1 = value1
module1name.setting2.setting2a = value2a
module1name.setting2.setting2b = value 2b
module2name.setting1 = value1

[live : general]
; live site
module1name.setting3 = livevalue3

[dev : general]
; development settings
module1name.setting3 = testvalue3

[rka : dev]
; Rob's specific settings
module1name.setting3 = testvalue3a



I then load using something like this:


if (getenv('ZF_CONFIG')) {
    $configSection = getenv('ZF_CONFIG');
$config = new Zend_Config(new Zend_Config_Ini('config.ini', $configSection));
} else {
    die('Not configured!');
}

ZF_CONFIG is set using SetEnv within Apache's virtual host section or a .htaccess on the relevant server.


There's nothing to stop you having a config file per module, in which case, I'd still use inheritance within the config file as it makes maintenance much easier. Do you really have that many configuration settings per module though?


Regards,

Rob...


Reply via email to