Welcome Guest, Not a member yet? Register   Sign In
Codeigniter how to conditionally load config files?

I am using CodeIgniter to write a application. I need to create something like this: - I will have: -

* my_config.php
* config_production.php
* config_development.php

Now, my_config.php will be autoloaded. From there, if it is production server config_production.php will be loaded. Else config_development.php will be loaded.

how should I do this?

I tried doing like this in my_config.php: -
if(gethostbyaddr ("") == 'hello.sabya'){
} else {

It is not working because, the "$this->config" is not initialized yet.

How can I achieve this?

Can you not just include the file with normal PHP?
include APPPATH.'config/config_development.php';

[eluser]Phil Sturgeon[/eluser]
That would work as long as you made the include in a config file that WAS being included correctly. Otherwise the config items wont accessable via $this->config->item().

Take a look at How to Support multiple production environments in CodeIgniter which should help you with some of this.

Phil, I think your link is a bit screwed up, it's

Which seems wrong, not to mention the fact it just goes to the news page, instead of said article
I think all that publicity of being mentioned on PHP Developer has gone to your head Wink

[eluser]Phil Sturgeon[/eluser]
That'll teach me to copy links directly from the address bar suggestions!

Thanks guys!

I got it working, like this: -
$ci = & get_instance();

if (gethostbyaddr ("") == 'production.example.com') {
    //Load production configuration
} elseif(gethostbyaddr ("") == 'staging.example.com') {
    //Load staging configuration
} else {
    //Load development configuration

Theme © iAndrew 2016 - Forum software by © MyBB