I wrote a pretty cool config function once:

<?php
        if (file_exists(realpath("../config/config.production.php")))
        {
                include_once("config.production.php");
                define("IS_DEV", 0);
        }
        else if (file_exists(realpath("../config/config.dev.php")))
        {
                include_once("config.dev.php");
                define("IS_DEV", 1);
        }
?>

so i just include that file, and it figures it out. the production  
config takes precedence over the dev config so if the folder contains  
that file then it will be included instead of dev, so don't have  
production config in dev ;-).

Inside config.dev.php i also made it so that it looked up different  
computer names and included that (incase diff. developers had  
different paths):

<?php
        $name_array = split("\.", strtolower(php_uname("n")));
        $name = $name_array[0];
        if (file_exists(realpath("../config/config.$name.php")))
        {
                include_once("config.$name.php");
        }
?>

I know that ruby on rails for example has a config file which has  
different settings based on environment (using YML) .. this technique  
probably works better than the one I posted.

> I use this pattern quite a lot. What I generally do, is store separate
> config files for each environment in a development directory in SVN,
> then run an install script that copies the file into place to set up
> the environment.
>
> eg:
>
> dev/config/local.config.php
> dev/config/staging.config.php
> dev/config/live.config.php
>
> These get copied to a config.php that is linked from the actual
> application, but is never checked in to source control.
>
> Regards,
> Mark
>
> >


--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

Reply via email to