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
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
I believe that PHP's parse_ini_file()
function only has access to constants in the global space and not in the class space.
I haven't been able to use My_Class::MYCONST
or My\Class::MYCONST
in any .ini file.
You can define constants in your application.ini file and then call them with the code below in controller.
public function init() {
//Getting constants from application.ini file
$registry = Zend_Registry::getInstance();
$this->_constants = $registry->app_config->constants;
}
where your constants are defined in application.ini file like below
;My Constants
constants.MY_CONSTANT="value"
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 theAPPLICATION_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 theapplication.ini
file likelogger.main.level = LOGLEVEL_WARNING
My pick would be the numeric value in the
application.ini
file like this :Take a look at
APPLICATION_PATH
andDATESTAMP
which are constants that I have defined in my index.php