Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup a Zend_Application with an application.ini and a user.ini

I am using Zend_Application and it does not feel right that I am mixing in my application.ini both application and user configuration.

What I mean with this is the following. For example, my application needs some library classes in the namespace MyApp_ . So in application.ini I put autoloaderNamespaces[] = "MyApp_". This is pure application configuration, no-one except a programmer would change these. On the other hand I put there a database configuration, something that a SysAdmin would change.

My idea is that I would split options between an application.ini and an user.ini, where the options in user.ini take preference (so I can define standard values in application.ini).

Is this a good idea? How can I best implement this? The idea's I have are

  • Extending Zend_Application to take multiple config files
  • Making an init function in my Bootstrap loading the user.ini
  • Parsing the config files in my index.php and pass these to Zend_Application (sounds ugly)

What shall I do? I would like to have the 'cleanest' solution, which is prepared for the future (newer ZF versions, and other developers working on the same app)

like image 774
Peter Smit Avatar asked Jan 10 '10 11:01

Peter Smit


2 Answers

I found a solution to this issue that may be new to framework version 1.10. When creating the Zend Application object, you can pass in 2 configuration file paths in the options array that get merged together:

$application = new Zend_Application(
    APPLICATION_ENV,
    array(
        'config' => array(
            APPLICATION_PATH . '/configs/application.ini',
            APPLICATION_PATH . '/configs/user.ini'
        ),
    )
);
like image 55
Troy Avatar answered Sep 16 '22 15:09

Troy


you know this will merge as much inis as you want?

in application.ini

[production]
config[] = APPLICATION_PATH "/configs/dsn.ini"
config[] = APPLICATION_PATH "/configs/error.ini"
...
like image 34
bas Avatar answered Sep 19 '22 15:09

bas