Accessing constants in config/main file

Hi all,

 I want to access a veriable from constant component file in the config/main.php file. For example,      

 I have a ConfigManager Class  in my component dir as  


class ConfigManager {

        public static $dbUserName = 'root';

        public static $dbPassword = 'test123';



And in config file I want to do it like this -




        'username'=> ConfigManager::$dbUserName,

        'password'=> ConfigManager::$dbPassword,



But it is giving require error. Can’t find class ConfigManager. Is it possible to do it like this?


The components aren’t loaded until after the config file. Not surprising, given that the config file contains the information needed to load them. You could include/require ConfigManager.php in your config file.

Let me ask one question: What do you win by using such a ConfigManager class?

Hi Mike,

Actually I have some other configuration parameters like

     $serverTimeZone = 'Asia/Calcutta';

  What I would like to have single configuration file that just need to be edited while configuring the application. So I want to have ConfigManager file to place all the configurations and it will configure rest of the application. 

    May be its not right idea&#33;

Please replay!

Thanks again.

There are lot of ways to do something similar. My favorite approach is to keep a file local.php in config/ that gets merged into the main.php config array. That way you can override/add settings in your local config file. Similar to this: