I've got a common set of functionality I'd like to embed into a Zend_Application
instance using the configs
parameter inside of that app's Zend_Config
instance. However, the slaved configuration file would like to be able to refer to things in a path relative to itself. For instance:
$/application/configs/application.ini:
[base]
config[] = APPLICATION_PATH "../CasCommon/Configs/common.ini
$/CasCommon/Configs/common.ini
[base]
resources.frontController.controllerDirectory[] = PATH_TO_THIS_IN_DIR "../Controllers"
resources.frontController.actionHelperPaths.Cas_Common_Helper = PATH_TO_THIS_IN_DIR "../ControllerHelpers"
;...
How might one accomplish such a thing?
PHP supports constants in Ini files, but unfortunately not magic constants, so you cannot use
__DIR__
, which would solve the problem. The easiest and most obvious thing would be defining the path to the application.ini file as a constant just like you did withAPPLICATION_PATH
, e.g.Then just load your
Zend_Application
regularly or instantiate a newZend_Config
and the constant will be evaluated like you wanted.Edit after comments
I find that argument about the above being not automagic enough moot. In a standard ZF project, the
APPLICATION_PATH
is defined in the index.php file and that's also where the default application.ini is loaded. All you have to do is add the constant there. The Ini file won't exist on it's own anyway so someone will have to call an external library at some point (likely you as the developer). The above solution requires one line of setup. Any other solution requires more work.If that is not good enough for you, you can extend
Zend_Application
to automatically add that constant before the application.ini gets loaded:Of course, you will still have to change index.php to use your extended
My_Zend_Application
then which is why I find this approach rather pointless given that you can also just add the constant in the index.php file.A custom
Zend_Application
will limit you to the application.ini of course because you cannot change the constant at runtime anymore. So if you need this functionality for multiple Ini files and not just the application.ini, extendZend_Config_Ini
and check each value for a Relative Path marker before it is returned, e.g.The above assumes you write your Ini files with something like
If that is still not what you are looking I can only encourage you once more to put up precise requirements. There is no point in offering 500 reputation when you are not going to accept any answers here because we failed to read your mind.