Merge pull request #1356 from thanpolas/new-config-load-sequence

New config load sequence
diff --git a/system/core/Common.php b/system/core/Common.php
index 4b733ac..159cc0d 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -231,21 +231,25 @@
 			return $_config[0];
 		}
 
-		// Is the config file in the environment folder?
-		if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
+		$file_path = APPPATH.'config/config.php';
+		$found = FALSE;
+		if (file_exists($file_path)) 
 		{
-			$file_path = APPPATH.'config/config.php';
+			$found = TRUE;
+			require($file_path);
 		}
 
-		// Fetch the config file
-		if ( ! file_exists($file_path))
+		// Is the config file in the environment folder?
+		if (defined(ENVIRONMENT) && file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
+		{
+			require($file_path);			
+		} 
+		elseif ( ! $found) 
 		{
 			set_status_header(503);
 			exit('The configuration file does not exist.');
 		}
 
-		require($file_path);
-
 		// Does the $config array exist in the file?
 		if ( ! isset($config) OR ! is_array($config))
 		{
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index da3be3a..3989b52 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -38,6 +38,7 @@
    -  Added some more doctypes.
    -  Updated all classes to be written in PHP 5 style, with visibility declarations and no ``var`` usage for properties.
    -  Moved error templates to "application/views/errors"
+   -  Global config files are loaded first, then environment ones. Environment config keys overwrite base ones, allowing to only set the keys we want changed per Env.
 
 -  Helpers
 
diff --git a/user_guide_src/source/libraries/config.rst b/user_guide_src/source/libraries/config.rst
index c81cad7..08d9c29 100644
--- a/user_guide_src/source/libraries/config.rst
+++ b/user_guide_src/source/libraries/config.rst
@@ -149,11 +149,13 @@
 -  Your own custom configuration files
 
 .. note::
-	CodeIgniter always tries to load the configuration files for
-	the current environment first. If the file does not exist, the global
-	config file (i.e., the one in application/config/) is loaded. This means
-	you are not obligated to place **all** of your configuration files in an
-	environment folder − only the files that change per environment.
+	CodeIgniter always loads the global config file first (i.e., the one in application/config/),
+	then tries to load the configuration files for the current environment.
+	This means you are not obligated to place **all** of your configuration files in an
+	environment folder. Only the files that change per environment. Additionally you don't
+	have to copy **all** the config items in the environment config file. Only the config items
+	that you wish to change for your environment. The config items declared in your environment
+	folders always overwrite those in your global config files.
 
 Helper Functions
 ================