[eluser]jmadsen[/eluser]
CI's idea of working with the Apache env variables is nice in some ways, but has the issue of not working from the command line
CIs cli syntax is also a little weird to work with, as all extra arguments get passed as variables to your function.
So I threw together this rather crude but I think effective hack:
Code:
if ((php_sapi_name() == 'cli') or defined('STDIN'))
{
$environment = 'localhost';
if (isset($argv))
{
$key = (array_search('--env', $argv));
$environment = $argv[$key +1];
unset($argv[$key], $argv[$key +1]);
}
define('ENVIRONMENT', $environment);
}
(This of course goes in your index.php, where you define your ENVIRONMENT )
You run it normally, but then can add "--env production" at the end to set your ENVIRONMENT. Yes, simple & crude :-)
Wonder if anyone has solved this in a different manner, or sees any issues with this code (not deployed at all yet, so use at own risk for now). I had considered getting fancy and rewriting the whole initialization bit with a library & pull in from vendor, but just seemed like overkill when CI is so restricted in what it accepts
Jeff