flexibleconfig Flexible configuration for Yii application.

  1. Features
  2. Settings
  3. Example 1
  4. Example 2
  5. Resources
  6. Change Log

The extension is designed for flexible application configuration. Represents the behavior for the СApplication class. Adds an object with one method - loadConfigure().


  • Easy connection configuration file;
  • Inheritance of configuration files;
  • Automatic load config from *_local.php;


  • string FConfig::configDir - path to the configuration file, defaults to 'application.config';
  • array FConfig::configs - array with a list of configurations, key - the name of the configuration, value - an array of configuration settings;
  • string FConfig::currentConfig - the name of the current configuration;

Each configuration has a property 'parent' - is a string with the name of the parent configuration.

Example 1

I need to have two different application configuration mode for the development and production server. Most of the settings they have the same, and some do not. To do this, I have three files in the folder config: main.php - contains general settings for all configurations; dev.php - contains specific design-time configuration; production.php - contains settings specific to the production.

index.php file I have contains the following code:


    $yii = 'yii/framework/yii.php';

    // remove the following lines when in production mode
    defined('YII_DEBUG') or define('YII_DEBUG', true);
    // specify how many levels of call stack should be shown in each log message
    defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 3);

        'behaviors' => array(
            'fconfig' => array(
                'class' => 'ext.FlexibleConfig.FConfig',
                'currentConfig' => 'dev',
                'configs' => array(
                    'dev' => array(
                        'parent' => 'main',
                    'production' => array(
                        'parent' => 'main',

In addition to the config folder is a file dev_local.php, which is automatically loaded after dev.php and overrides the necessary local settings.

Example 2







if (strpos($_SERVER['HTTP_HOST'], 'localhost') !== false) {
    defined('YII_DEBUG') or define('YII_DEBUG',true);
    defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
    define('YII_ENV', 'dev');
} else {
    defined('YII_DEBUG') or define('YII_DEBUG',false);
    defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',1);
    define('YII_ENV', 'production');

return array(
    'name'=>'My Web Application',

    'behaviors' => array(
        'fconfig' => array(
            'class' => 'ext.FlexibleConfig.FConfig',
            'currentConfig' =>  YII_ENV,
            'configs' => array(
                'dev' => array(),
                'production' => array(),
                'test' => array(),



Change Log

January 26, 2011
  • Added multiple inheritance
    January 23, 2011
  • First version
4 0
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Developed by: karagodin
Created on: Jan 23, 2011
Last updated: 13 years ago


show all