diff options
Diffstat (limited to 'system/core')
-rw-r--r-- | system/core/Config.php | 143 |
1 files changed, 107 insertions, 36 deletions
diff --git a/system/core/Config.php b/system/core/Config.php index ab69c0720..7e0443c1f 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -30,6 +30,7 @@ class CI_Config { var $config = array(); var $is_loaded = array(); + var $_config_paths = array(APPPATH); /** * Constructor @@ -44,7 +45,7 @@ class CI_Config { */ function CI_Config() { - $this->config =& get_config(); + $this->config =& get_config(); log_message('debug', "Config Class Initialized"); } @@ -60,52 +61,66 @@ class CI_Config { function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); + $loaded = FALSE; - if (in_array($file, $this->is_loaded, TRUE)) + foreach($this->_config_paths as $path) { - return TRUE; - } - - if ( ! file_exists(APPPATH.'config/'.$file.EXT)) - { - if ($fail_gracefully === TRUE) + $file_path = $path.'config/'.$file.EXT; + + if (in_array($file_path, $this->is_loaded, TRUE)) { - return FALSE; + $loaded = TRUE; + continue; } - show_error('The configuration file '.$file.EXT.' does not exist.'); - } - - include(APPPATH.'config/'.$file.EXT); - if ( ! isset($config) OR ! is_array($config)) - { - if ($fail_gracefully === TRUE) + if ( ! file_exists($path.'config/'.$file.EXT)) { - return FALSE; + continue; } - show_error('Your '.$file.EXT.' file does not appear to contain a valid configuration array.'); - } + + include($file_path); - if ($use_sections === TRUE) - { - if (isset($this->config[$file])) + if ( ! isset($config) OR ! is_array($config)) + { + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.'); + } + + if ($use_sections === TRUE) { - $this->config[$file] = array_merge($this->config[$file], $config); + if (isset($this->config[$file])) + { + $this->config[$file] = array_merge($this->config[$file], $config); + } + else + { + $this->config[$file] = $config; + } } else { - $this->config[$file] = $config; + $this->config = array_merge($this->config, $config); } + + $this->is_loaded[] = $file_path; + unset($config); + + $loaded = TRUE; + log_message('debug', 'Config file loaded: '.$file_path); } - else + + if ($loaded === FALSE) { - $this->config = array_merge($this->config, $config); + if ($fail_gracefully === TRUE) + { + return FALSE; + } + show_error('The configuration file '.$file.EXT.' does not exist.'); } - $this->is_loaded[] = $file; - unset($config); - - log_message('debug', 'Config file loaded: config/'.$file.EXT); return TRUE; } @@ -191,19 +206,52 @@ class CI_Config { */ function site_url($uri = '') { - if (is_array($uri)) + if ($uri == '') { - $uri = implode('/', $uri); + if ($this->item('base_url') == '') + { + return $this->item('index_page'); + } + else + { + return $this->slash_item('base_url').$this->item('index_page'); + } } - if ($uri == '') + if ($this->item('enable_query_strings') == FALSE) { - return $this->slash_item('base_url').$this->item('index_page'); + if (is_array($uri)) + { + $uri = implode('/', $uri); + } + + $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); + return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; } else { - $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix'); - return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix; + if (is_array($uri)) + { + $i = 0; + $str = ''; + foreach ($uri as $key => $val) + { + $prefix = ($i == 0) ? '' : '&'; + $str .= $prefix.$key.'='.$val; + $i++; + } + + $uri = $str; + } + + if ($this->item('base_url') == '') + { + return $this->item('index_page').'?'.$uri; + } + else + { + return $this->slash_item('base_url').$this->item('index_page').'?'.$uri; + } } } @@ -235,7 +283,30 @@ class CI_Config { { $this->config[$item] = $value; } + + // -------------------------------------------------------------------- + /** + * Assign to Config + * + * This function is called by the front controller (CodeIgniter.php) + * after the Config class is instantiated. It permits config items + * to be assigned or overriden by variables contained in the index.php file + * + * @access private + * @param array + * @return void + */ + function _assign_to_config($items = array()) + { + if (is_array($items)) + { + foreach ($items as $key => $val) + { + $this->set_item($key, $val); + } + } + } } // END CI_Config class |