Config File Helper

Functions to aid in reading and saving config items to and from configuration files.

The config files are expected to be found in the APPPATH .’/config’ folder.  It does not currently work within modules.

Author

Lonnie Ezell

Summary
Config File HelperFunctions to aid in reading and saving config items to and from configuration files.
Functions
read_config()Returns an array of configuration settings from a single config file.
write_config()Saves the passed array settings into a single config file located in the /config directory.
read_db_config()Retrieves the config/database.php file settings.
write_db_config()Saves the settings to the config/database.php file.

Functions

read_config()

function read_config($file,  
$fail_gracefully = TRUE)

Returns an array of configuration settings from a single config file.

Parameters

$fileThe config file to read.
$fail_gracefullytrue/false.  Whether to show errors or simply return false.

Return

An array of settings, or false on failure (when $fail_gracefully = true).

write_config()

function write_config($file = '',
$settings = null)

Saves the passed array settings into a single config file located in the /config directory.

Parameters

$fileThe config file to write to.
$settignsAn array of key/value pairs to be written to the file.

Return

true/false

read_db_config()

function read_db_config($environment = null,
$new_db =  NULL,
$fail_gracefully =  TRUE)

Retrieves the config/database.php file settings.  Plays nice with CodeIgniter 2.0’s multiple environment support.

Parameters

$environment(Optional) The envinroment to get.  If empty, will return all environments.
$new_db (str)(Optional) Returns an new db config array with parameter as $db active_group name
$fail_gracefullytrue/false.  Whether to halt on errors or simply return false.

Return

An array of database settings or abrupt failure (when $fail_gracefully == FALSE)

write_db_config()

function write_db_config($settings = null)

Saves the settings to the config/database.php file.

Parameters

$settingsThe array of database settings.  Should be in the format: array( ‘main’ => array( ‘setting1’ => value, ...  ), ‘development’ => array( ...  ) );

Return

true/false

function read_config($file,  
$fail_gracefully = TRUE)
Returns an array of configuration settings from a single config file.
function write_config($file = '',
$settings = null)
Saves the passed array settings into a single config file located in the /config directory.
function read_db_config($environment = null,
$new_db =  NULL,
$fail_gracefully =  TRUE)
Retrieves the config/database.php file settings.
function write_db_config($settings = null)
Saves the settings to the config/database.php file.
Close