Search code examples
zend-frameworkzend-config

Using class constants in Zend_Config_Ini application.ini


I've got several constants defined in one of my classes and would like to use on of them in my application.ini, is this possible?

logger.main.level = \My\App\Logger::WARNING

This does not seem to work, it just parses it as a string


Solution

  • If you want to use the value of a constant in your application.ini you need to define the constant in the /public/index.php file (see the APPLICATION_PATH).

    If you want to do it cleanly in your code I would eiter do it using the log level manually with the numeric value (assuming the constant is numeric as in Zend_Log) since this value is not likely to change or do it in the index.php and define a new constant named something like LOGLEVEL_WARNING (you can then get the value of the constant statically from your class), which you will be able to use in the application.ini file like logger.main.level = LOGLEVEL_WARNING

    My pick would be the numeric value in the application.ini file like this :

    resources.log.stream.writerName = "Stream"
    resources.log.stream.writerParams.stream = APPLICATION_PATH "/../data/logs/application_" DATESTAMP ".log"
    resources.log.stream.writerParams.mode = "a"
    resources.log.stream.filterName = "Priority"
    resources.log.stream.filterParams.priority = 4
    

    Take a look at APPLICATION_PATH and DATESTAMP which are constants that I have defined in my index.php