Last active
May 14, 2016 08:40
-
-
Save bhuvidya/f80756f9bdea6fb4d0f7216a25ec1e56 to your computer and use it in GitHub Desktop.
Set environment for Craft CMS console application/plugin. The following php script is put in a directory like $WEBSITE_ROOT/utils.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* a front end for yiic.php that looks for env on cmdline and sets CRAFT_ENVIRONMENT | |
* accordingly. I put this script in a folder called "utils" in the root of my website | |
* install. So instead of doing something like | |
* php $root/craft/app/etc/console/yiic.php plugin cmd | |
* you would call | |
* php $root/utils/yiic_frontend.php --env=envname plugin cmd | |
* where "envname" is the config environment you wish to use. | |
*/ | |
for ($i = 1; $i < count($_SERVER['argv']); $i++) { | |
$arg = $_SERVER['argv'][$i]; | |
if (strpos($arg, '--env=') === 0) { | |
$env = explode('=', $arg)[1]; | |
printf("---- setting env \"%s\"\n", $env); | |
define('CRAFT_ENVIRONMENT', $env); | |
array_splice($_SERVER['argv'], $i, 1); | |
break; | |
} | |
} | |
require(__DIR__ . '/../craft/app/etc/console/yiic.php'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment