Tag: codeigniter

Codeigniter Environments

This is going to be a quick post… actually all my codeigniter related posts will be quick hints and tips to make your codeigniter development easier.

This particular tip relates to productions vs development environments. Did you know that seperating production/development environments it CI is really easy?

Heres how:

  1. Inside your application/config folder simple add 2 new folders as follows
    1. application/config/production
    2. application/config/development
  2. Next
    1. Grab a copy of autoload.php, database.php and email.php if you have a email config file and place them into each of the folders /production & /development respectively.
  3. Time to edit your index.php file in the root folder of your site.

Find the following line of code in your index.php file:

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

Replace with:

$env = $_SERVER['HTTP_HOST'] == 'yourlocaldevdomain.dev' ? 'development' : 'production';
define('ENVIRONMENT', $env);

Voila, thats it – CI will now use either the production or development folders based on your host domain.


Brendan (IgnitedCoder)