Welcome Guest, Not a member yet? Register   Sign In
CI in a multi-developer environment
#1

[eluser]darrenm[/eluser]
Hi

As I only seem to come round here asking questions, I thought I’d post up something I find really useful that may help someone out.

I often need to work in a multi-developer environment with people in different locations and everyone submitting to SVN.

As CI can have environment-specific config values spread over a number of files (main config, database config etc) it can become a pain when committing to SVN as you either have to exclude files or be careful what you update. Same problem would apply to FTP.

So I came up with a working practice that means a single set of core files that’s easy for each of the devs to customise to their local environment.

1. Download CodeIgniter (I take it from SVN) to a location outside of your webroot.

2. Add two folders to your webroot, ‘assets’ and ‘code’. Assets speaks for itself, code is a copy of the ‘application’ folder from CI

3. Copy index.php from the CodeIgniter folder into your webroot

3. Move all config values that can change in a different hosting environment out of standard files into a new config file named config_CI_ENV_CONFIG.php. Where CI_ENV_CONFIG is a string of your choice. This file will look something like so:

Code:
$config['base_url']    = 'http://ci/';
$config['index_page'] = '';

… any other values …

$config['db']['dbdriver'] = 'mysql';
$config['db']['dbprefix'] = '';
$config['db']['pconnect'] = TRUE;
$config['db']['db_debug'] = FALSE;
$config['db']['cache_on'] = FALSE;
$config['db']['cachedir'] = '';
$config['db']['char_set'] = 'utf8';
$config['db']['dbcollat'] = 'utf8_general_ci';
$config['db']['hostname'] = 'localhost';
$config['db']['username'] = 'root';
$config['db']['password'] = '';
$config['db']['database'] = 'ci';
$config['db']['db_debug'] = TRUE;

4. Adjust your index.php to define the constant right at the top:
Code:
define('CI_ENV_CONFIG','darren');

Also in this file, adjust your system and application folder values to suit your filesystem
Code:
$system_folder = "D:/websites/CodeIgniter_core/CodeIgniter_1.7.0/system";
$application_folder = "D:/Projects/codeigniter/http/code";

5. Add my Environment Library and add it as the first item in your autoload config (also remove database from config if you have it)
Code:
class Environment {
  function Environment() {
    $this->CI =& get_instance();
    if(defined('CI_ENV_CONFIG') ) {
      // load config file
      $this->CI->load->config('config_'.CI_ENV_CONFIG);

      // load database
      $db = $this->CI->config->item('db');
      if($db) {
        $this->CI->load->database($db);
      }
    }
  }
}

With that all set up, the only file that changes from system to system is index.php – which you simply exclude from SVN updates.

I’ve found it’s saved loads of hassle, you can have different devs on completely different platforms and concentrate on the project rather than configuration clashes. Even with only one developer it's useful to be able to have separate 'live' and 'local' configs.

Hope someone finds that helpful
#2

[eluser]Jeremy Gimbel - Conflux Group[/eluser]
This looks interesting.

Currently I run my CI development environment with 3 separate configurations, local development, staging and production.

I move the application folder outside of the system folder and then I don't add the config folder to the SVN repository. So far it works well, though it could be a pain if config changes were being made that would affect settings other than the folder locations and database info.

jeremy
#3

[eluser]Phil Sturgeon[/eluser]
Can't much see why you would need different URL's as you can just use a virtual host, and there is no need for full paths for system or application as the relative ones work fine.

Setting a constant to pick which database group to use however is a handy idea. I use this sometimes to set settings for local, production, live, but I guess it makes sense to make local-phil, local-jimmy, production and live instead.




Theme © iAndrew 2016 - Forum software by © MyBB