<p>If you use the <a href="http://buildwithcraft.com/docs/php-constants#craft-environment" rel="nofollow">CRAFT_ENVIRONMENT</a> PHP constant at the beginning of <code>yiic.php</code>, then you'll be able to tell it which multi-environment config to use.</p>

<pre><code>define('CRAFT_ENVIRONMENT', 'dev');
</code></pre>

CC BY-SA 3.0
2015-07-27T17:22:07.753Z
2015-07-27T17:22:07.753Z
Brad Bell
<p>ok i used the answer brad bell posted above and enhanced it slightly. i wanted to be able to specify the target environment on the command line, and i didn't want to edit a framework file to do it.</p>

<p>so i created the following file, yiic_frontend.php, placed it in $root/utils (a new dir), and call it using <code>php $root/utils/yiic_frontend.php --env=envname plugin cmd</code>:</p>

<pre><code>&lt;?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 &lt; 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');
</code></pre>

CC BY-SA 3.0
2016-05-14T08:47:54.160Z
2016-05-14T08:47:54.160Z
bhu Boue vidya
<p>I am trying to write a console plugin for yiic so that I can import data programmatically from an old site.</p>

<p>I have a multi configuration setup for the craft site. Is there an elegant way to tell yiic which configuration I am targeting (so that it opens the right database etc)?</p>

<plugins>
Elegant Way To Pass Configuration To yiic?
# Elegant Way To Pass Configuration To yiic?

(Asked by: username_0 on 2015-07-27)

I am trying to write a console plugin for yiic so that I can import data programmatically from an old site.

I have a multi configuration setup for the craft site. Is there an elegant way to tell yiic which configuration I am targeting (so that it opens the right database etc)?

**Tags:** plugins

---

## 2 answers

### Answer by username_1 on 2015-07-27. Score: 2 | Accepted answer

If you use the CRAFT_ENVIRONMENT PHP constant at the beginning of yiic.php, then you'll be able to tell it which multi-environment config to use.
define('CRAFT_ENVIRONMENT', 'dev');


---

### Answer by username_0 on 2016-05-14. Score: 4

ok i used the answer brad bell posted above and enhanced it slightly. i wanted to be able to specify the target environment on the command line, and i didn't want to edit a framework file to do it.
so i created the following file, yiic_frontend.php, placed it in $root/utils (a new dir), and call it using php $root/utils/yiic_frontend.php --env=envname plugin cmd:


---

