Using a dynamicly defined constant in the index.php file, CodeIgniter can be set up to run on two servers.
I have found this really speeds up my development time, especially if used along with Bazaar Upload for Web ( http://bazaar-vcs.org/BazaarUploadForWebDev ).
With this feature, the same CodeIgniter installation can run on two servers without the need to change variables.
Step 1
To implement this feature into CodeIgniter, edit the index.php file, and include the following code at the top.
if ($_SERVER['SERVER_NAME'] == 'localhost')
{
//Development enviroment.
define('SITE_LIVE', FALSE);
}
else
{
//Live enviroment.
define('SITE_LIVE', TRUE);
}
The code determines if CodeIgniter is running on a localhost, and then sets the SITE_LIVE constant to FALSE, or to TRUE if it’s not.
Step 2
Alter the “config.php” file ( ../application/config/config.php ), by replacing the original “base_url” variable, with the code below.
if (SITE_LIVE)
{
//Live base URL
$config['base_url'] = "http://neillyons.info/";
}
else
{
//Development base URL
$config['base_url'] = "http://localhost/";
}
The if statement sets the “base_url” variable depending on whether the site is Live or in Development.
Step 3
Alter the “database.php” file ( ../application/config/database.php ), by replacing the original variable with the code below.
if (SITE_LIVE)
{
//Live site database settings.
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
}
else
{
//Development site database settings.
$active_group = "default";
$active_record = TRUE;
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
}
Let me know what you think of this feature.