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().

Features

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

Settings

  • 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:

<?php

    $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);

    require_once($yii);
    Yii::createWebApplication(array(
        'behaviors' => array(
            'fconfig' => array(
                'class' => 'ext.FlexibleConfig.FConfig',
                'currentConfig' => 'dev',
                'configs' => array(
                    'dev' => array(
                        'parent' => 'main',
                    ),
                    'production' => array(
                        'parent' => 'main',
                    ),
                ),
            ),
        ),
    ))->loadConfigure()->run();

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

index.php

<?php

    $yii='yii/framework/yii.php';
    $config=include(dirname(__FILE__).'/protected/config/main.php');

    require_once($yii);
    Yii::createWebApplication($config)->loadConfigure()->run();

config/main.php

<?php

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(),
            ),
        ),
    ),

	'params'=>array(
		'adminEmail'=>'ekaragodin@gmail.com',
	),
);

Resources

Change Log

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

Downloads

show all