title: Yii console with different configs
body: <p>In the web application we use same code and modules with different configs like:</p>
  
  <p>in index.php file app will decide, wchin config to turn:</p>
  
  <pre class="lang-php prettyprint-override"><code>switch($_SERVER['HTTP_HOST']){
      default:
          $yii=$webRoot.'/framework/yiilite.php';
          $config = $webRoot.'/protected/config/main.php';
      break;
          case 'someurl.com':
                ...
          break;
          ...
  }
  </code></pre>
  
  <p>But, how can I do it with console application?
  The reason in that I use different databases ant etc.</p>
  
  <p>is it possible to do something like this:</p>
  
  <pre><code>$ ./protected/yiic --application=myappname [all defined commands as default]
  </code></pre>
  
  <p>in the code a</p>
  
  <pre><code>--application
  </code></pre>
  
  <p>will set with which console config to work</p>
  
  <p><strong>more explanation</strong></p>
  
  <p>my answer to @Joe Miller
  But the problem is, how choose theme?
  I did in the files foloowings:</p>
  
  <p>in protectes/yiic</p>
  
  <pre><code>$__appId = null;
  for( $__i=1,$__max=count($argv); $__i&lt;$__max; ++$__i ) {
      if ( strpos($argv[$__i],'--appid',0) === 0 ) {
          $__appId = substr($argv[$__i], 8);
          unset($argv[$__i]);
      }
  }
  
  require_once(dirname(__FILE__).'/yiic.php');
  </code></pre>
  
  <p>and in protected/yiic.php</p>
  
  <pre><code>$__appIdsList = array(
      'my_site_1',
      'my_site_2',
      'my_site_3',
      'my_site_4',
  );
  
  $yiic=dirname(__FILE__).'/../framework/yiic.php';
  $config=dirname(__FILE__).'/config/console_'.$__appId.'.php';
  
  require_once($yiic);
  </code></pre>
  
  <p>and it works and it catchs that config file what I need</p>
  
  <pre><code>./protected/yiic --appid=my_site_1
  </code></pre>
  
  <p>bu when I`m trying to do migrate</p>
  
  <pre><code>./protected/yiic --appid=my_site_1 migrate
  </code></pre>
  
  <p>the app cant recognize comman and gives me migrates help list</p>
  
  <p><strong>And final conslusion (I solved it)</strong></p>
  
  <p>I`d like to add transperent console command without affecting it to other execution of builtin console commands and custom console commands.</p>
  
  <p>Another requirement is, solve this issue on a low-level approach, without inheritance or overloading other classes or methods.</p>
  
  <p>So, my solution is:</p>
  
  <p>in protected/yiic</p>
  
  <pre><code>#!/usr/bin/env php
  &lt;?php
  
  $__appId = null;
  for( $__i=1,$__max=count($argv); $__i&lt;$__max; ++$__i ) {
      if ( strpos($argv[$__i],'--appid',0) === 0 ) {
          $__appId = substr($argv[$__i], 8);
          unset($argv[$__i]);
          unset($_SERVER['argv'][$__i]);
          $argv = $_SERVER['argv'] = array_values($argv);
      }
  }
  
  require_once(dirname(__FILE__).'/yiic.php');
  </code></pre>
  
  <p>and in /protected/yiic.php</p>
  
  <pre><code>&lt;?php
  
  // change the following paths if necessary
  $__appIdsList = array(
      'app_1',
      'app_2',
  );
  
  $yiic=dirname(__FILE__).'/../framework/yiic.php';
  $config=dirname(__FILE__).'/config/console_'.$__appId.'.php';
  
  if ( !is_file($config) ) {
      die("Error: There is no or wrong parametr appid. Please set parametr or correct. Example -appid={application_name}\n\tThe list of available appid:\n\t\t - ".implode("\n\t\t - ", $__appIdsList));
  }
  
  require_once($yiic);
  </code></pre>
  
  <p>and now it is possible to set param "appid" in any place of command line, like</p>
  
  <pre><code>./protected/yiic  migrate --appid=app_1
  </code></pre>
  
  <p>and it acts only in that app what we need</p>
  
  <p>PS: in any case, thanks @Joe Miller</p>