phpzend-frameworkconfigurationzend-application

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

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)


Solution

  • 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'
            ),
        )
    );