Welcome Guest, Not a member yet? Register   Sign In
Retrieving configs from a file other than config.php
#2

[eluser]TheFuzzy0ne[/eluser]
CodeIgniter supports multiple environments. You can each have a config file for your own environment, and put some logic into your index.php file to set the right environment according to the URL being used.

Here's a snippet from my index.php file:
Code:
/*
*---------------------------------------------------------------
* APPLICATION ENVIRONMENT
*---------------------------------------------------------------
*
* You can load different configurations depending on your
* current environment. Setting the environment also influences
* things like logging and error reporting.
*
* This can be set to anything, but default usage is:
*
*     development
*     testing
*     production
*
* NOTE: If you change these, also change the error_reporting() code below
*
*/

// Prefer HOSTNAME in the environment, which will be set in Apache.
// use `uname -n' as a backup.
$hostname = (isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : php_uname("n");

switch($hostname) {
    case 'dev.example.com':
        define('ENVIRONMENT', 'development');
        ini_set('display_errors', 1);
        error_reporting(E_ALL);
        break;

    case 'www.example.com':
        define('ENVIRONMENT', 'production');
        break;

    default: trigger_error('$hostname is set to an unknown value', E_USER_ERROR);
}

Now create a directory for each environment (apart from production), and each put your individual configuration files in each. CodeIgniter will load the appropriate configuration file automatically, and use those settings.

You can see more about handling multiple environments here: http://ellislab.com/codeigniter/user-gui...ments.html

Hope this helps.


Messages In This Thread
Retrieving configs from a file other than config.php - by El Forum - 03-23-2013, 08:23 AM
Retrieving configs from a file other than config.php - by El Forum - 03-23-2013, 08:37 AM
Retrieving configs from a file other than config.php - by El Forum - 03-24-2013, 07:32 AM
Retrieving configs from a file other than config.php - by El Forum - 03-24-2013, 08:06 AM
Retrieving configs from a file other than config.php - by El Forum - 03-24-2013, 08:07 AM
Retrieving configs from a file other than config.php - by El Forum - 03-24-2013, 11:35 PM
Retrieving configs from a file other than config.php - by El Forum - 03-25-2013, 04:50 PM
Retrieving configs from a file other than config.php - by El Forum - 03-25-2013, 05:36 PM
Retrieving configs from a file other than config.php - by El Forum - 03-25-2013, 08:53 PM
Retrieving configs from a file other than config.php - by El Forum - 03-26-2013, 01:54 AM
Retrieving configs from a file other than config.php - by El Forum - 03-26-2013, 12:31 PM
Retrieving configs from a file other than config.php - by El Forum - 03-26-2013, 12:49 PM
Retrieving configs from a file other than config.php - by El Forum - 03-26-2013, 03:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB