CI_Config Class Reference

List of all members.


Public Member Functions

 CI_Config ()
 Constructor.
 load ($file= '', $use_sections=FALSE, $fail_gracefully=FALSE)
 Load Config File.
 item ($item, $index= '')
 Fetch a config file item.
 slash_item ($item)
 Fetch a config file item - adds slash after item.
 site_url ($uri= '')
 Site URL.
 system_url ()
 System URL.
 set_item ($item, $value)
 Set a config file item.

Public Attributes

 $config = array()
 $is_loaded = array()

Detailed Description

Definition at line 29 of file Config.php.


Member Function Documentation

CI_Config::CI_Config (  ) 

Constructor.

Sets the $config data from the primary config.php file as a class variable

public

Parameters:
string the config file name
boolean if configuration values should be loaded into their own section
boolean true if errors should just return false, false if an error message should be displayed
Returns:
boolean if the file was successfully loaded or not

Definition at line 45 of file Config.php.

References get_config(), and log_message().

00046         {
00047                 $this->config =& get_config();
00048                 log_message('debug', "Config Class Initialized");
00049         }       

Here is the call graph for this function:

CI_Config::item ( item,
index = '' 
)

Fetch a config file item.

public

Parameters:
string the config item name
string the index name
bool 
Returns:
string

Definition at line 124 of file Config.php.

Referenced by site_url().

00125         {       
00126                 if ($index == '')
00127                 {       
00128                         if ( ! isset($this->config[$item]))
00129                         {
00130                                 return FALSE;
00131                         }
00132 
00133                         $pref = $this->config[$item];
00134                 }
00135                 else
00136                 {
00137                         if ( ! isset($this->config[$index]))
00138                         {
00139                                 return FALSE;
00140                         }
00141 
00142                         if ( ! isset($this->config[$index][$item]))
00143                         {
00144                                 return FALSE;
00145                         }
00146 
00147                         $pref = $this->config[$index][$item];
00148                 }
00149 
00150                 return $pref;
00151         }

Here is the caller graph for this function:

CI_Config::load ( file = '',
use_sections = FALSE,
fail_gracefully = FALSE 
)

Load Config File.

public

Parameters:
string the config file name
Returns:
boolean if the file was loaded correctly

Definition at line 60 of file Config.php.

References $config, log_message(), and show_error().

00061         {
00062                 $file = ($file == '') ? 'config' : str_replace(EXT, '', $file);
00063         
00064                 if (in_array($file, $this->is_loaded, TRUE))
00065                 {
00066                         return TRUE;
00067                 }
00068 
00069                 if ( ! file_exists(APPPATH.'config/'.$file.EXT))
00070                 {
00071                         if ($fail_gracefully === TRUE)
00072                         {
00073                                 return FALSE;
00074                         }
00075                         show_error('The configuration file '.$file.EXT.' does not exist.');
00076                 }
00077         
00078                 include(APPPATH.'config/'.$file.EXT);
00079 
00080                 if ( ! isset($config) OR ! is_array($config))
00081                 {
00082                         if ($fail_gracefully === TRUE)
00083                         {
00084                                 return FALSE;
00085                         }
00086                         show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.');
00087                 }
00088 
00089                 if ($use_sections === TRUE)
00090                 {
00091                         if (isset($this->config[$file]))
00092                         {
00093                                 $this->config[$file] = array_merge($this->config[$file], $config);
00094                         }
00095                         else
00096                         {
00097                                 $this->config[$file] = $config;
00098                         }
00099                 }
00100                 else
00101                 {
00102                         $this->config = array_merge($this->config, $config);
00103                 }
00104 
00105                 $this->is_loaded[] = $file;
00106                 unset($config);
00107 
00108                 log_message('debug', 'Config file loaded: config/'.$file.EXT);
00109                 return TRUE;
00110         }

Here is the call graph for this function:

CI_Config::set_item ( item,
value 
)

Set a config file item.

public

Parameters:
string the config item key
string the config item value
Returns:
void

Definition at line 234 of file Config.php.

00235         {
00236                 $this->config[$item] = $value;
00237         }

CI_Config::site_url ( uri = ''  ) 

Site URL.

public

Parameters:
string the URI string
Returns:
string

Definition at line 192 of file Config.php.

References item(), and slash_item().

00193         {
00194                 if (is_array($uri))
00195                 {
00196                         $uri = implode('/', $uri);
00197                 }
00198 
00199                 if ($uri == '')
00200                 {
00201                         return $this->slash_item('base_url').$this->item('index_page');
00202                 }
00203                 else
00204                 {
00205                         $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
00206                         return $this->slash_item('base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix;
00207                 }
00208         }

Here is the call graph for this function:

CI_Config::slash_item ( item  ) 

Fetch a config file item - adds slash after item.

The second parameter allows a slash to be added to the end of the item, in the case of a path.

public

Parameters:
string the config item name
bool 
Returns:
string

Definition at line 166 of file Config.php.

Referenced by site_url(), and system_url().

00167         {
00168                 if ( ! isset($this->config[$item]))
00169                 {
00170                         return FALSE;
00171                 }
00172 
00173                 $pref = $this->config[$item];
00174 
00175                 if ($pref != '' && substr($pref, -1) != '/')
00176                 {       
00177                         $pref .= '/';
00178                 }
00179 
00180                 return $pref;
00181         }

Here is the caller graph for this function:

CI_Config::system_url (  ) 

System URL.

public

Returns:
string

Definition at line 218 of file Config.php.

References slash_item().

00219         {
00220                 $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
00221                 return $this->slash_item('base_url').end($x).'/';
00222         }

Here is the call graph for this function:


Member Data Documentation

CI_Config::$config = array()

Definition at line 31 of file Config.php.

Referenced by load().

CI_Config::$is_loaded = array()

Definition at line 32 of file Config.php.


The documentation for this class was generated from the following file: