Skip to content

Loading…

New config load sequence #1356

Merged
merged 9 commits into from

7 participants

@thanpolas

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.

@alexbilbie

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

@thanpolas

@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?

@alexbilbie

A bang is a !

@alexbilbie

This line should should read

else if ( ! $found)

@narfbg

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

@alexbilbie

Good point @narfbg

@thanpolas

Thanks @narfbg ! Hope all looks ok now @alexbilbie

@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

@timw4mail

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.

@ericbarnes

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.

@alexbilbie

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

@cryode

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.

@philsturgeon

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

@thanpolas

Modified docs and changelog as per @philsturgeon's request

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


Signed-off-by: dchill42 <dchill42@gmail.com>
1eeebdb
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 committed
    automatic list formatting was broken
  2. @thanpolas
  3. @thanpolas
  4. @thanpolas
  5. @thanpolas
  6. @thanpolas

    Merge branch 'new-config-load-sequence' of github.com:thanpolas/CodeI…

    thanpolas committed
    …gniter into new-config-load-sequence
Showing with 19 additions and 12 deletions.
  1. +11 −7 system/core/Common.php
  2. +1 −0 user_guide_src/source/changelog.rst
  3. +7 −5 user_guide_src/source/libraries/config.rst
View
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)
{
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))
{
View
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
View
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.