summaryrefslogtreecommitdiffstats
path: root/system/core/Config.php
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2011-03-09 11:08:36 +0100
committerPhil Sturgeon <email@philsturgeon.co.uk>2011-03-09 11:08:36 +0100
commit93ca71552d9a3e28eeaa00dd10755d20b2cbf32e (patch)
tree660233f2ec631e5730731491d2fd244fe15f7df8 /system/core/Config.php
parenta9924b8352aa18869677bea0182c45e2a7e2ce37 (diff)
parent2f8b27efeb0a39c24eddf89cf31ea0fd113a6b71 (diff)
Merged recent Core changes and fixed conflict.
Diffstat (limited to 'system/core/Config.php')
-rw-r--r--system/core/Config.php72
1 files changed, 39 insertions, 33 deletions
diff --git a/system/core/Config.php b/system/core/Config.php
index 7fc804482..75f945efd 100644
--- a/system/core/Config.php
+++ b/system/core/Config.php
@@ -47,6 +47,24 @@ class CI_Config {
{
$this->config =& get_config();
log_message('debug', "Config Class Initialized");
+
+ // Set the base_url automatically if none was provided
+ if ($this->config['base_url'] == '')
+ {
+ if (isset($_SERVER['HTTP_HOST']))
+ {
+ $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
+ $base_url .= '://'. $_SERVER['HTTP_HOST'];
+ $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
+ }
+
+ else
+ {
+ $base_url = 'http://localhost/';
+ }
+
+ $this->set_item('base_url', $base_url);
+ }
}
// --------------------------------------------------------------------
@@ -56,6 +74,8 @@ class CI_Config {
*
* @access public
* @param string the config file name
+ * @param boolean if configuration values should be loaded into their own section
+ * @param boolean true if errors should just return false, false if an error message should be displayed
* @return boolean if the file was loaded correctly
*/
function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
@@ -63,9 +83,9 @@ class CI_Config {
$file = ($file == '') ? 'config' : str_replace(EXT, '', $file);
$loaded = FALSE;
- foreach($this->_config_paths as $path)
- {
- $file_path = $path.'config/'.$file.EXT;
+ foreach ($this->_config_paths as $path)
+ {
+ $file_path = $path.'config/'.ENVIRONMENT.'/'.$file.EXT;
if (in_array($file_path, $this->is_loaded, TRUE))
{
@@ -73,11 +93,17 @@ class CI_Config {
continue;
}
- if ( ! file_exists($path.'config/'.$file.EXT))
+ if ( ! file_exists($file_path))
{
- continue;
+ log_message('debug', 'Config for '.ENVIRONMENT.' environment is not found. Trying global config.');
+ $file_path = $path.'config/'.$file.EXT;
+
+ if ( ! file_exists($file_path))
+ {
+ continue;
+ }
}
-
+
include($file_path);
if ( ! isset($config) OR ! is_array($config))
@@ -118,9 +144,9 @@ class CI_Config {
{
return FALSE;
}
- show_error('The configuration file '.$file.EXT.' does not exist.');
+ show_error('The configuration file '.ENVIRONMENT.'/'.$file.EXT.' and '.$file.EXT.' do not exist.');
}
-
+
return TRUE;
}
@@ -185,14 +211,7 @@ class CI_Config {
return FALSE;
}
- $pref = $this->config[$item];
-
- if ($pref != '' && substr($pref, -1) != '/')
- {
- $pref .= '/';
- }
-
- return $pref;
+ return rtrim($this->config[$item], '/').'/';
}
// --------------------------------------------------------------------
@@ -208,14 +227,7 @@ class CI_Config {
{
if ($uri == '')
{
- if ($this->item('base_url') == '')
- {
- return $this->item('index_page');
- }
- else
- {
- return $this->slash_item('base_url').$this->item('index_page');
- }
+ return $this->slash_item('base_url').$this->item('index_page');
}
if ($this->item('enable_query_strings') == FALSE)
@@ -225,8 +237,9 @@ class CI_Config {
$uri = implode('/', $uri);
}
+ $index = $this->item('index_page') == '' ? '' : $this->slash_item('index_page');
$suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
- return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix;
+ return $this->slash_item('base_url').$index.trim($uri, '/').$suffix;
}
else
{
@@ -244,14 +257,7 @@ class CI_Config {
$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;
- }
+ return $this->slash_item('base_url').$this->item('index_page').'?'.$uri;
}
}