For today I am going to show you how to create a settings.php file to store your database connection and general config settings. The reason I use this method is because I am creating applications for general public usage and not all want or care about the framework driving the site. They just need a simple way to add their details and then have the script running. For this reason I create the settings.php in the site root which does two things. 1. Keeps them from having to edit files a few folders deep. 2. Simplifies the release package by not overwriting their files during upgrades.
My basic setup is like this. First create the settings.php file. Second I open up the config/database.php and copy the values into my settings file. Third I open config/config.php and find any items that I think a user would want to change or should change. I never include things in the settings file that is dependent on my setup such as prefix, query strings, etc.
Once everything is in my settings file I alter the config/database.php and delete all the $db array values. Then I add:
$active_group = "default"; $active_record = TRUE; include(APPPATH .'/settings.php');
Then for the config/config.php file I do basically the same thing. Delete everything I included in the settings.php file and then at the top add:
include(APPPATH .'/settings.php');
Because the database and config files use a different array it doesn’t clash by including this file in both places.
Be sure and read my other CodeIgniter tips!
