Config.php
Go to the documentation of this file.00001 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 class CI_Config {
00030
00031 var $config = array();
00032 var $is_loaded = array();
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 function CI_Config()
00046 {
00047 $this->config =& get_config();
00048 log_message('debug', "Config Class Initialized");
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
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 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 function item($item, $index = '')
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 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 function slash_item($item)
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 }
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 function site_url($uri = '')
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 }
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 function system_url()
00219 {
00220 $x = explode("/", preg_replace("|/*(.+?)/*$|", "\\1", BASEPATH));
00221 return $this->slash_item('base_url').end($x).'/';
00222 }
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 function set_item($item, $value)
00235 {
00236 $this->config[$item] = $value;
00237 }
00238
00239 }
00240
00241
00242
00243
00244