Skip to content


Subversion checkout URL

You can clone with
Download ZIP


New config load sequence #1356

merged 9 commits into from

7 participants


Load the config.php from base config directory, then load any config in the environment directory.

This in effect causes the keys in environment's config to overwrite base ones, allowing to have config.php files with only the keys we want changed, instead having to copy/paste the whole config.php and edit the few keys we want changed per environment.


Sorry to be anal, can you make sure your code follows the coding standard; braces should be on new lines and there should be a space either side of a bang


@alexbilbie that's not anal, that's proper code review :) I indented as per the styleguide...

However i did not understand what you mean by "there should be a space either side of a bang" ... bang?


A bang is a !


This line should should read

else if ( ! $found)


Actually, it should also be elseif instead of else if and true on line 238 should be TRUE.


Good point @narfbg


Thanks @narfbg ! Hope all looks ok now @alexbilbie


I like the principle of this proposal however it seems wasteful to first load the original config file and then load the environment config.

I think it should be swapped around so that it first tries to load an environment config then if one isn't found load the default config.

What do you think @narfbg @philsturgeon @ericbarnes


I like this way - you have a cascading effect which means you can set defaults for each environment and then customize. The other way mean every variable has to be set in every environment.


Yeah I like the cascading so you wouldn't have to include the whole config array in your environment. So with that the env config should be much lighter and only include those which are different. But with a fallback it will have to load both anyway.


Having thought about it for a bit I agree that the cascading route it probably best.


I agree. It's always annoying to copy / paste an entire config file just to change a base_url or something of that nature.

Then again I usually add logic to my config.php to prevent multiple files in the first place, but I still think it's useful.


Could you add this to the user_guide and the changelog please?


Modified docs and changelog as per @philsturgeon's request

@narfbg narfbg merged commit f3b95d3 into bcit-ci:develop
@dchill42 dchill42 referenced this pull request from a commit in dchill42/CodeIgniter
@dchill42 dchill42 Adapted main and autoload config bootstrapping to also comply with #1356

Signed-off-by: dchill42 <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 14, 2012
  1. @thanpolas
Commits on May 20, 2012
  1. @thanpolas
Commits on May 21, 2012
  1. @thanpolas
Commits on May 31, 2012
  1. @philsturgeon

    Merge pull request #1413 from vlakoff/develop

    philsturgeon authored
    automatic list formatting was broken
  2. @thanpolas
  3. @thanpolas
  4. @thanpolas

    Edit to meet CI coding standards

    thanpolas authored thanpolas committed
  5. @thanpolas
  6. @thanpolas

    Merge branch 'new-config-load-sequence' of…

    thanpolas authored
    …gniter into new-config-load-sequence
This page is out of date. Refresh to see the latest.
18 system/core/Common.php
@@ -231,21 +231,25 @@ function &get_config($replace = array())
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)
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))
1  user_guide_src/source/changelog.rst
@@ -38,6 +38,7 @@ Release Date: Not Released
- 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
12 user_guide_src/source/libraries/config.rst
@@ -149,11 +149,13 @@ folders:
- 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
Something went wrong with that request. Please try again.