Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Command-Line w/ Environment Configs
#4

[eluser]jmadsen[/eluser]
/*
Our goal is to send:
php index.php cron daily_tasks important_job 123 --env production

and have it run http://mysite.com/cron/daily_tasks/important_job/123
using the production environment

*/

// it's in two places - let's be smart
define('DEFAULT_ENV', 'development');

// detects if it is a command line request
if ((php_sapi_name() == 'cli') or defined('STDIN'))
{
$environment = DEFAULT_ENV;
if (isset($argv))
{
// grab the --env argument, and the one that comes next

$key = (array_search('--env', $argv));
$environment = $argv[$key +1];

// get rid of them so they don't get passed in to our method as parameter values

unset($argv[$key], $argv[$key +1]);
}
define('ENVIRONMENT', $environment);
}

if (!defined('ENVIRONMENT')) define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : DEFAULT_ENV);


Here's a quick write up: http://codebyjeff.com/blog/2013/10/setti...ommandline


Messages In This Thread
Codeigniter Command-Line w/ Environment Configs - by El Forum - 07-05-2012, 07:22 PM
Codeigniter Command-Line w/ Environment Configs - by El Forum - 07-05-2012, 11:40 PM
Codeigniter Command-Line w/ Environment Configs - by El Forum - 07-06-2012, 07:17 AM
Codeigniter Command-Line w/ Environment Configs - by El Forum - 10-05-2013, 03:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB