CodeIgniter Forums
Multiple Code Igniter Config Folders - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Multiple Code Igniter Config Folders (/showthread.php?tid=10359)

Pages: 1 2


Multiple Code Igniter Config Folders - El Forum - 07-28-2008

[eluser]adamfairholm[/eluser]
I've seen variations on this in different places around the site, but none to my knowledge in this setup - in theory it should work, but for some reason it doesn't like me. Any help in pointing out my logical flaw would be much appreciated!

So I have a server with server domains, and they are several sites that I'd like to run off one application. However, since they are different sites, they should each have their own config folder (not just file, since they each have some custom config files of their own).

I have my folder structure set up like this:

Code:
-system
-application
--config
---mysite1
----all the config files
---mysite2
----all the config files
-mysite1.com
--css
--img
--index.php
-mysite2.com
--css
--img
--index.php

In each index.php file I have the absolute paths to the application and system folder, and then I have this:

Code:
$config_individual_folder = "/**my_serverpath**/application/config/mysite1";

define('CFPB', $config_individual_folder.'/');

In system/codeigniter/CodeIgniter I have replaced

Code:
require(APPPATH.'config/constants'.EXT);

with

Code:
require(CFPB.'constants'.EXT);

and in system/libraries/Config.php I changed:

Code:
if ( ! file_exists(APPATH.'config/'.$file.EXT))
        {
            if ($fail_gracefully === TRUE)
            {
                return FALSE;
            }
            show_error('The configuration file '.$file.EXT.' does not exist.');
        }
            
        include(APPATH.'config/'.$file.EXT);


Code:
if ( ! file_exists(CFPB.$file.EXT))
        {
            if ($fail_gracefully === TRUE)
            {
                return FALSE;
            }
            show_error('The configuration file '.$file.EXT.' does not exist.');
        }
            
        include(CFPB.$file.EXT);

As far as I can tell and from what I've read around on the threads in bits in pieces of what I'm trying to do, this should work, but I only get a blank screen.

Is there some flaw in my reasoning here?


Multiple Code Igniter Config Folders - El Forum - 07-28-2008

[eluser]Randy Casburn[/eluser]
Hey frogmoves -- It looks like this should work for "site1" right?

Do you have logging turn on by any chance? Can you report what's being dumped into your CI logs?

Thanks,

Randy


Multiple Code Igniter Config Folders - El Forum - 07-28-2008

[eluser]adamfairholm[/eluser]
Whattup Randy!

Since the logging threshold is in the config.php file, I can't set it and turn on logging unless I am missing something.

Adam


Multiple Code Igniter Config Folders - El Forum - 07-28-2008

[eluser]Randy Casburn[/eluser]
hahahahah -- man I'm funny! :red:

No really...that was goofy. Sorry. Um...I'm thinking...


Multiple Code Igniter Config Folders - El Forum - 07-28-2008

[eluser]Randy Casburn[/eluser]
think I've found it...

in index.php at line 93

Code:
if (is_dir($application_folder))
{
    define('APPPATH', $application_folder.'/');
}
else
{
    if ($application_folder == '')
    {
        $application_folder = 'application';
    }

    define('APPPATH', BASEPATH.$application_folder.'/');
}

You see, APPPATH is set here as one of three options. I'm not sure what you're doing later. Is it possible that APPPATH is inconsistent in 1...* places among all these scripts that you've modified?

It would stand to reason that your configs at mysite1 would not be found then.

Randy


Multiple Code Igniter Config Folders - El Forum - 07-28-2008

[eluser]adamfairholm[/eluser]
I've solved it!

Randy - that's funny about the error logging - it's confusing, because where the config file would be loaded (Common.php), there isn't any error logging as far as I can see.

I figured out which one of the three APPPATH variables it was dealing with, and I put in copies of the config files where CI apparently was looking for them so I could do some debugging. I found that libraries/Config.php being loaded in the Codeigniter.php file was only loading my custom config files (as specified through autoload.php).

The difference is I want a whole config FOLDER rather than a separate config FILE which I think was tripping up my logic. Turns out as I looked through CI, each config file is loaded in a separate place (not in libaries/Config.php as I had thought before I really carefully read through codeigniter/Codeigniter.php).

So, for anyone who might be doing the same thing, here is what you need to change to create an entirely new config FOLDER. This may be somewhere else, but I couldn't find it.

Step 1: Modifying index.php

In the bootstrap index.php file for a site, after the application folder variable, add a variable for the server path to your special config variable folder.

Code:
$application_folder = "/**server_path**/application";

$config_folder = "/**server_path**/application/config/this_site";

It doesn't have to be in the application folder.

Then, after defining BASEPATH, add your own global variable and define it as your server path from the $config_folder variable:

Code:
define('CFP', $config_folder.'/');


Step 2: Replacing APPPATH in key places

By default Code Igniter uses the APPATH global variable to load different config files. All you need to do is find these APPATH instances and replace them with CFP. Keep in mind that you may need to modify the hard-coded part of the path too.

For example, this:

Code:
include(APPATH.'config/'.$file.EXT);

Becomes:

Code:
include(CFP.$file.EXT);

Here are the locations of these instances (with the exceptions of mimes and smileys which I couldn't find).

codeigniter/Codeignter.php - line 52 (constants)
codeigniter/Common.php - lines 145 & 150 (main config)
libraries/Config.php - lines 69 & 78 (custom config files)
libraries/Loader.php - line 890 (autoload)
database/DB.php - line 30 (database)
libraries/Hooks - line 69 (hooks)
libraries/Router - line 82 (routes)
libraries/User_agent - line 87 (user_agent)

I'll post it when I find the smileys and mimes, but until then, this has worked for me.

WARNING: I have not tested this very vigorously. If I run into any disasters with this method, I'll post that as well.


Multiple Code Igniter Config Folders - El Forum - 07-28-2008

[eluser]Randy Casburn[/eluser]
Well I'm glad you got this all sorted out. I'm sort of not glad for you that you went and hacked up so much of the CI core. And if my experience is any guide...in about three weeks...you won't be either...teehee ;-P

I hope this all works the way you hope you want it too.

Please do yourself a favor right now. Create a file in the root of your CI install named MODIFICATIONS.txt and summarize these changes. Specifically the changes to the APPPATH thing.

Good luck frogmoves!

Randy


Multiple Code Igniter Config Folders - El Forum - 07-28-2008

[eluser]adamfairholm[/eluser]
Thanks Randy - yeah this is verrryy far from anything I'd put into production but its something to play around with and see if it breaks.

As always, thanks for the help Randy!


Multiple Code Igniter Config Folders - El Forum - 12-14-2010

[eluser]takasia[/eluser]
Question - is it possible to load the application config like this form the default config file?
I tried and it didn't worked, but maybe there is some way...

equire_once CONFIGPATH.'config'.EXT;

This I have in my index.php:

$this_app_config_folder = "the_path";

// after define('BASEPATH', str_replace("\\", "/", $system_path));
define('CONFIGPATH', str_replace("\\", "/", $this_app_config_folder));

But it seems that the CONFIGPATH just doesn't get defined - I can echo a BASEPATH etc from the default config.php but CONFIGPATH is just empty.


Multiple Code Igniter Config Folders - El Forum - 12-14-2010

[eluser]takasia[/eluser]
It worked - I'm sorry, there was missing */ in my index.php, so silly, god...

Anyway, without messing with the core files:

Put this in your application/config/config.php -> the default one:

require_once CONFIGPATH.‘config’.EXT;

(the same goes to the rest of the config files)

In the index.php:
$this_app_config_folder = “the_path”;
define(‘CONFIGPATH’, str_replace(”\\”, “/”, $this_app_config_folder));