title: Yii Command line - How to initialize my entire web app and call other controller actions via yiic?
body: <p>Update - I was able to solve this by adding application.controllers.* to config/console.php like so:</p>
  
  <pre><code>'import'=&gt;array(
          'application.models.*',
          'application.components.*',
          'application.controllers.*',
          'application.extensions.CAdvancedArBehavior',
          'application.extensions.eUploadedImage.*',
         ),
  </code></pre>
  
  <p>then  calling the actions in the cli command like this:</p>
  
  <pre><code>$myCtrl=new CopyNumberNewSegController(NULL);
  $myCtrl-&gt;actionBatchImport($libraries,$action);
  </code></pre>
  
  <p>I have a simple yiic command in protected/commands/dBManagerCommand.php that I can run from the command line:</p>
  
  <pre><code>class DBManagerCommand extends CConsoleCommand
  {
      public $verbose=false;
      public $divider="--------------------------------------------------------------------------\n";
      public $title="DB Manager Command\n";
      public function actionImportAnalysis($libraries=false,$action='incomplete') {
          echo $this-&gt;divider;
          echo $this-&gt;title;
          echo $this-&gt;divider;
          echo 'Importing '.$action ." analysis data from file system...\n";
          echo $this-&gt;divider;
  
          switch ($action) {
  
              case 'incomplete':
  
                  CopyNumberNewSegController::batchImport($libraries,$action);
  
  
                  break;
          }
  
          return 0;
      }
  }
  </code></pre>
  
  <p>Running it produces the following error. Apparently it can't find my other controllers. I want to run methods from existing controllers in the rest of my application.  This is run from the bash shell (ignore code colors) </p>
  
  <pre><code>yiic dbmanager importAnalysis --action=incomplete
  --------------------------------------------------------------------------
  DB Manager Command
  --------------------------------------------------------------------------
  Importing incomplete analysis from file system...
  --------------------------------------------------------------------------
  PHP Error[2]: include(CopyNumberNewSegController.php): failed to open stream: No such file or directory
      in file /var/www/html/mioncoseq/pub/framework/YiiBase.php at line 418
  #0 /var/www/html/mioncoseq/pub/framework/YiiBase.php(418): autoload()
  #1 unknown(0): autoload()
  #2 /var/www/html/mioncoseq/pub/protected/commands/dBManagerCommand.php(21): spl_autoload_call()
  #3 unknown(0): DBManagerCommand-&gt;actionImportAnalysis()
  #4 /var/www/html/mioncoseq/pub/framework/console/CConsoleCommand.php(141): ReflectionMethod-&gt;invokeArgs()
  #5 /var/www/html/mioncoseq/pub/framework/console/CConsoleCommandRunner.php(65): DBManagerCommand-&gt;run()
  #6 /var/www/html/mioncoseq/pub/framework/console/CConsoleApplication.php(91): CConsoleCommandRunner-&gt;run()
  #7 /var/www/html/mioncoseq/pub/framework/base/CApplication.php(162): CConsoleApplication-&gt;processRequest()
  #8 /var/www/html/mioncoseq/pub/framework/yiic.php(33): CConsoleApplication-&gt;run()
  #9 /var/www/html/mioncoseq/pub/protected/yiic.php(7): require_once()
  #10 /var/www/html/mioncoseq/pub/protected/yiic(4): require_once()
  </code></pre>
  
  <p>So then how can i load those controller methods? I'm sure there is a proper way to do this that will initialize my entire app, without trying to manually include those controller files.</p>
  
  <p>Thanks everyone! </p>
  
  <hr>
  
  <p>In response to the criticism about misuse of MVC architecture below, I'm going to paste this response here because the comment field is not long enough.  </p>
  
  <p>Firstly, I wouldn't pre-load all controllers for the web interface, but for this purpose it solved the problem and works fine. The import method initially takes requests thru the controller but then calls model methods where appropriate for db and file system level logic and operations. (And yes I do have other import model classes dedicated for this purpose, mostly because of behavior-related memory leaks in Yii). </p>
  
  <p>The idea that one should not do any logic in a controller is just wrong, imo. In this case I've chosen to make import methods in controllers that do some input filtering logic, because there are a large number of inputs that the user (human or cron) needs to submit, and this needs to occur before we get to the task of parsing files into the db.  This controller import method parses files based on user input and passes the pre-filtered data to the model method.  I've chosen to do this because file input data is actually untrusted user input and I needed to do some pre-processing based on the user request params.  Yes you could do this in a model method, but it would result in either processing request data in the model, or passing a large number of arguments and data around, which is a hassle and increases memory usage.   </p>