Codeigniter.tvbeta

Codeigniter video tutorials and screencasts

Dynamically distinguish between development, staging and production servers

No more need to keep different settings for different servers

Author: Joost van Veen

2011/09/12 Screenshot from video tutorial

Wouldn't it be great if you didn't have to keep different config files for your development, staging and production server? No more mix-ups, lost config files or sudden crashes after an uncareful deployment? The answer lies in dynamically setting your ENVIRONMENT constant, and using it to decide which settings to use. Simple but effective!

Though this constant has been baked into Codeigniter from version 2.0.1, actual implementation still requires some handywork. This quicktip takes you through all the steps.

EDIT: you do not need to code switch statements in config.php and database.php. Thats just my preferred way of doing things. It dates from the days of before ENVIRONMENT was added to Codeigniter, and I use to add this myself. Instead, you can store config and databse files in a folder like /config/production/config.php. Read more about it in the user guide.

Download the source code for this tutorial