Page 1 of 1

Switching from development to production

Posted: Thu Sep 10, 2009 2:41 pm
by cols2910
Hi everyone

I have a config.ini file that contains the following

[development]

debug = true
database.host = localhost
database.database = dbname
database.username = username
database.password = password


[production]

debug = false
database.host = localhost
database.database = dbLive
database.username = root
database.password = pass

I have used parse_ini to parse the file and I can then retrieve the values of the various settings. However, is there an easy way to tell my application to use the settings in [development] or [production]? I'm sure I did this before but for the life of me I can't figure out what I did.

Many thanks,
Cols2910

Re: Switching from development to production

Posted: Thu Sep 10, 2009 3:59 pm
by cols2910
Aha. Thats what I have been missing.

Many thanks McInfo

Regards,
Cols2910

Re: Switching from development to production

Posted: Fri Sep 11, 2009 1:10 pm
by cols2910
Hi McInfo (or anyone else who wishes to jump in here)

I have been wracking my brains trying to access the desired variables which I can by doing

$config = parse_ini_file("config/config.ini", true);

if($config['development.debug'])
{
// do sometihing
}

However, I'm still unsure as to how to tell my application to i=use either the development settings or the production settings. I have tried numerous combinations such as

$config[development][debug]

but to no avail. Using 'development.debug' works but how would I tell the application to use the [development]->settings or the [production]->settings?

Many thanks,
Cols2910

Re: Switching from development to production

Posted: Fri Sep 11, 2009 1:38 pm
by cols2910
Okay I think I finally figured it out

$environment = 'development'; //switch this between production / development
$config = parse_ini_file("config/config.ini", true);

$settings = $config[$environment]['database.username'];

I'm sure there is maybe a better way to do this so if anyone has any suggestions, please feel free to post them here.

Thanks,
Cols2910

Re: Switching from development to production

Posted: Sat Sep 12, 2009 11:03 am
by cols2910
Good idea McInfo. I'll run with that suggestion.

Many thanks,
Cols2910