CodeIgniter Forums

Full Version: Multiple sites, multiple config files, one app / system
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]olimortimer[/eluser]
Hi all,

New here, but I've been playing around with Codeigniter for a while - big thanks to everyone involved in making a fantastic framework!

This might be a bit of a dumb question, but I couldn't find any answers on how to achieve this...

I'm creating a CMS to use amongst my clients, and would like a single install of the base code, which they all access. This is obviously easy, by changing the path to the applications and system folder in the unique index.php file for each site.

However, each site will require it's own database (obviously), amongst other config items.

The question is; How would I go about loading different config files for each site, rather than loading the base config file in application/config ?

Any help would be greatly appreciated.

El Forum

[eluser]CroNiX[/eluser]
Have the config files named after the domain name, then use $_SERVER['HTTP_HOST'] to find out what domain you are on and load the corresponding config.

I do something similar with 1 code base, and each site is just symlinked to that.

El Forum

[eluser]Kamarg[/eluser]
Two options spring to mind. Use one config file for all sites and add a switch statement based on the domain. Or CodeIgniter supports seperate config directories based on the defined ENVIRONMENT. So you can have config/client1 where you have define('ENVIRONMENT', 'client1') in your main index.php.

El Forum

[eluser]olimortimer[/eluser]
I didn't think of the ENVIRONMENT definition...doh!

Is there any way of having the config file in the client's website directory, rather than in the application/config dir, and load it within index.php ?

Ie,

/application
-/config.php (default)
-/database.php (default)
/system

/client1
-/index.php (client1 specific)
-/config.php (client1 specific)
-/database.php (client1 specific)

/client2
-/index.php (client2 specific)
-/config.php (client2 specific)
-/database.php (client2 specific)

El Forum

[eluser]Kamarg[/eluser]
I suppose you could add the client's directory to the _config_path member of the CI_Config core class. You'd need to insert it at the beginning of the array though since the load method stops as soon as it finds the first matching file name regardless of location.

El Forum

[eluser]CroNiX[/eluser]
[quote author="olimortimer" date="1327439254"]
Is there any way of having the config file in the client's website directory, rather than in the application/config dir, and load it within index.php ?[/quote]Yes, symlink them.

El Forum

[eluser]olimortimer[/eluser]
Thanks for all the help...and apologies for the 'noob' questions!

I've got the application and system folders elsewhere now, and simply accessing them via granting permissions and ../../application etc - I tried symlink, but the way my server is setup meant I had to grant permissions anyway, and then add either symlinks or ../../folder as the path.

Now, the next question is...

I'd like to have a config file for each client in their folder, which will have their specific database details in - I know it would be easier to have different environments etc, but I'd like to upload everything at once to the client site, and it all works without diving into the core files.

How would I accomplish this? Can I somehow 'override' the default database config file?

El Forum

[eluser]olimortimer[/eluser]
I'm trying to accomplish the above using a subclass (MY_Config.php) as explained here (http://www.caseymclaughlin.com/2011/04/s...deigniter/), but running into a problem:

It seems to load the file, as I can var_dump in the construct, but it doesn't hit the load() function.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Config extends CI_Config {

    function __construct()
    {
        parent::__construct();
    }

    /**
  * Load a config file - Overrides built-in CodeIgniter config file loader
  *
  * @param string $file
  * @param boolean $use_sections
  * @param boolean $fail_gracefully
  */
function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
  parent::load($file, $use_sections, $fail_gracefully);

  //Local settings override permanent settings always.
  if (is_readable(FCPATH . 'config.php'))
   parent::load('config.php', $use_sections, $fail_gracefully);
}
}

/* End of file MY_Config.php */
/* Location: ./system/application/core/MY_Config.php */


I also tried loading the config from the database, using another idea posted on CI, but I couldn't get the fetch function to run either:
http://codeigniter.com/wiki/Config_Extend_to_Database

What am I doing wrong!?

El Forum

[eluser]CroNiX[/eluser]
For the first one it looks like that is looking in the same location (FCPATH) as index.php for the config.php file. Is that where you put it?

El Forum

[eluser]olimortimer[/eluser]
Yeah that's right, but it doesn't even fire the load function
Pages: 1 2