Search code examples
zend-frameworkzend-config

How do i access the url variable defined in the Zend Framework config.ini


[dev]
great.url="www.google.com"
[test : dev]
great.url="www.yahoo.com"
[prod : test]
great.url="www.aol.com"

I have my own functions which return the Config of the environment that is used(DEV,TEST,OR PROD) . Now my problem is $myclassinstance->getConfig()->great->url; (when i say this it is returning url correctly in dev) where as in test it is returning notice "Notice: Trying to get property of non-object in file test.php on line no 19" this error is coming due to empty of this statement ($myclassinstance->getConfig()->great->url;).it is returning correctly in dev . What might be the problem.


Solution

  • It must be defaulting to dev. To fix it, you need to do something like this:

    $config = new Zend_Config_Ini('/path/to/config.ini', 'prod');
    $myclassinstance->setConfig($config);
    

    or depending on how you have things setup:

    $myclassinstance->config = $config;
    

    Then your code should work:

    $myclassinstance->getConfig()->great->url;
    

    Documentation is here: http://framework.zend.com/manual/en/zend.config.adapters.ini.html