From 4df8b2276bbcc7f025a41b0d09f2f8cd7927b51a Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 15 Dec 2010 14:23:14 +0000 Subject: ['base_url'] is now empty by default and will guess what it should be. --- system/core/Config.php | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index bdd1b8333..506af0d99 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -47,6 +47,25 @@ 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'] == '') + { + // Base URL (keeps this crazy sh*t out of the config.php + if(isset($_SERVER['HTTP_HOST'])) + { + $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? '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); + } } // -------------------------------------------------------------------- @@ -185,14 +204,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 +220,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) @@ -244,14 +249,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; } } -- cgit v1.2.3-24-g4f1b From fb5523855cb0592abe8e8720d7019fa82acfb054 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 15 Dec 2010 14:29:21 +0000 Subject: Revised the base_url auto-generation detection of protocol as some servers will not send off. --- system/core/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index 506af0d99..081f1d899 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -54,7 +54,7 @@ class CI_Config { // Base URL (keeps this crazy sh*t out of the config.php if(isset($_SERVER['HTTP_HOST'])) { - $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http'; + $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']); } -- cgit v1.2.3-24-g4f1b From de3dbc36dab42d86c66d76efd6fdb1d1dce71ce8 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Mon, 27 Dec 2010 17:41:02 +0000 Subject: Languages can now be placed in packages folders, and added ->load->get_package_paths(). --- system/core/Config.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index 081f1d899..8ecfba73a 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -51,7 +51,6 @@ class CI_Config { // Set the base_url automatically if none was provided if ($this->config['base_url'] == '') { - // Base URL (keeps this crazy sh*t out of the config.php if(isset($_SERVER['HTTP_HOST'])) { $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http'; -- cgit v1.2.3-24-g4f1b From cee8075e2f8fdeb0d8516b5af8ae7cd7754ac513 Mon Sep 17 00:00:00 2001 From: joelcox Date: Sat, 15 Jan 2011 23:09:47 +0100 Subject: Split basic configuration in three environments, providing fallback to global --- system/core/Config.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index 8ecfba73a..56e3bccd8 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 $environment = ENVIRONMENT; var $_config_paths = array(APPPATH); /** @@ -74,6 +75,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) @@ -82,8 +85,8 @@ class CI_Config { $loaded = FALSE; foreach($this->_config_paths as $path) - { - $file_path = $path.'config/'.$file.EXT; + { + $file_path = $path.'config/'.ENVIRONMENT.'/'.$file.EXT; if (in_array($file_path, $this->is_loaded, TRUE)) { @@ -91,9 +94,12 @@ class CI_Config { continue; } - if ( ! file_exists($path.'config/'.$file.EXT)) + if ( ! $file_path) { - continue; + if ( ! file_exists($path.'config/'.$file.EXT)) + { + $file_path = $path.'config/'.$file.EXT; + } } include($file_path); @@ -136,9 +142,9 @@ class CI_Config { { return FALSE; } - show_error('The configuration file '.$file.EXT.' does not exist.'); + show_error('The configuration file '.$environment.'/'.$file.EXT.' does not exist.'); } - + return TRUE; } -- cgit v1.2.3-24-g4f1b From 96b72ae4dc1334431f95d3f3151409f656a19725 Mon Sep 17 00:00:00 2001 From: joelcox Date: Sun, 16 Jan 2011 14:16:18 +0100 Subject: Fixed bug that prevented global config from loading on error --- system/core/Config.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index 56e3bccd8..ae914414d 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -94,14 +94,17 @@ class CI_Config { continue; } - if ( ! $file_path) + if ( ! file_exists($file_path)) { - if ( ! file_exists($path.'config/'.$file.EXT)) + log_message('debug', 'Config for '.ENVIRONMENT.' environment is not found. Trying global config.'); + $file_path = $path.'config/'.$file.EXT; + + if ( ! file_exists($file_path)) { - $file_path = $path.'config/'.$file.EXT; + continue; } } - + include($file_path); if ( ! isset($config) OR ! is_array($config)) @@ -142,7 +145,7 @@ class CI_Config { { return FALSE; } - show_error('The configuration file '.$environment.'/'.$file.EXT.' does not exist.'); + show_error('The configuration file '.ENVIRONMENT.'/'.$file.EXT.' and '.$file.EXT.' do not exist.'); } return TRUE; -- cgit v1.2.3-24-g4f1b From 5c59c7dc3254616b18057922ce012f22c18b147b Mon Sep 17 00:00:00 2001 From: joelcox Date: Sun, 16 Jan 2011 18:53:37 +0100 Subject: Cleaned up environment class variable which isn't used anymore in current implementation --- system/core/Config.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index ae914414d..d6b97d7ef 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -30,7 +30,6 @@ class CI_Config { var $config = array(); var $is_loaded = array(); - var $environment = ENVIRONMENT; var $_config_paths = array(APPPATH); /** -- cgit v1.2.3-24-g4f1b From 705a3eec44635f3fada8daa2886d409e6447ca12 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 19 Jan 2011 13:46:07 +0000 Subject: Avoid double-slashed on the base_url by only slashing index_page if it is actually set. --- system/core/Config.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index 8ecfba73a..7f501911c 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -229,8 +229,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 { -- cgit v1.2.3-24-g4f1b From 5d5895fd1084cd62721afd4c5f875eb2f99eefc4 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:27:07 -0500 Subject: Whitespace cleanup in core/ --- system/core/Config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/Config.php') diff --git a/system/core/Config.php b/system/core/Config.php index da22222dc..75f945efd 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -51,7 +51,7 @@ class CI_Config { // Set the base_url automatically if none was provided if ($this->config['base_url'] == '') { - if(isset($_SERVER['HTTP_HOST'])) + if (isset($_SERVER['HTTP_HOST'])) { $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http'; $base_url .= '://'. $_SERVER['HTTP_HOST']; @@ -83,7 +83,7 @@ class CI_Config { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); $loaded = FALSE; - foreach($this->_config_paths as $path) + foreach ($this->_config_paths as $path) { $file_path = $path.'config/'.ENVIRONMENT.'/'.$file.EXT; -- cgit v1.2.3-24-g4f1b