title: Console app in yii fails to include AR model
body: <p>I want to schedule to run console command in yii.
  I composed php script and tried it in web-app - works well.
  Yet, when i put it as <a href="http://www.yiiframework.com/doc/guide/1.1/ru/topics.console" rel="nofollow">console command</a> the cron send the following message:</p>
  
  <pre><code>PHP Error[2]: include(User.php): failed to open stream: No such file or directory
      in file /home/srv50213/htdocs/framework/YiiBase.php at line 427
  #0 /home/srv50213/htdocs/framework/YiiBase.php(427): autoload()
  #1 unknown(0): autoload()
  #2 /home/srv50213/htdocs/doc/protected/commands/ReportMailerCommand.php(20): spl_autoload_call()
  #3 unknown(0): ReportMailerCommand-&gt;actionIndex2()
  #4 /home/srv50213/htdocs/framework/console/CConsoleCommand.php(172): ReflectionMethod-&gt;invokeArgs()
  #5 /home/srv50213/htdocs/framework/console/CConsoleCommandRunner.php(71): ReportMailerCommand-&gt;run()
  #6 /home/srv50213/htdocs/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner-&gt;run()
  #7 /home/srv50213/htdocs/framework/base/CApplication.php(180): CConsoleApplication-&gt;processRequest()
  #8 /home/srv50213/htdocs/framework/yiic.php(33): CConsoleApplication-&gt;run()
  #9 /home/srv50213/htdocs/doc/protected/yiic.php(8): require_once()
  </code></pre>
  
  <p>Seems like autoload() does not function properly.
  For console app $config i use config/console.php where i've inserted the db setting (from main.php and user setting).  </p>
  
  <pre><code>'components'=&gt;array(
      'db'=&gt;array(            
              // настройки для конфигурации 
          'connectionString' =&gt; 
          'mysql:host=localhost;dbname=xxx',
          'emulatePrepare' =&gt; true,
          'schemaCachingDuration' =&gt; 3600,
          'username' =&gt; 'xxx',
          'password' =&gt; 'xxx',
          'charset' =&gt; 'utf8',
          'tablePrefix' =&gt; 'yiiapp_', 
          'class'     =&gt; 'CDbConnection'          
      ),
      'user'=&gt;array(      
          'class' =&gt; 'WebUser', 
          //'class' =&gt; 'application.components.User',
          // enable cookie-based authentication
          'allowAutoLogin'=&gt;true,
      ),  
   )
  </code></pre>
  
  <p>The script is smth. like this:</p>
  
  <pre><code>public function actionIndex2($args) 
  {    
      $users = User::model()-&gt;findAllByPk( array(177) );  
      foreach($users as $user)
      {         
          $query = "SELECT  e.id, e.Subject
                          FROM  `yiiapp_doc_events` AS e
                          LEFT JOIN  `yiiapp_doc_event_users` AS u ON e.id = u.eventId
                          WHERE e.StatusId NOT IN (5,7)  
                          AND u.userId = {$user-&gt;id}
                          GROUP BY e.id";
          $queryResult = Yii::app()-&gt;db-&gt;createCommand($query)-&gt;queryAll(); 
  
          if ($queryResult)
          {   
              foreach($queryResult as $res)
              {
                  $i++;
                  $link = Yii::app()-&gt;createAbsoluteUrl('docEvents/update', array('id'=&gt;$res['id']));
                  $table .= "&lt;tr&gt;&lt;td&gt; {$i} &lt;/td&gt;&lt;td&gt; &lt;a href='{$link}'&gt;{$res['id']}&lt;/a&gt; &lt;/td&gt;&lt;td&gt; &lt;a href='{$link}'&gt;{$res['Subject']}&lt;/a&gt; &lt;/td&gt;&lt;/tr&gt;";                
              }
              //echo $table . '&lt;/table&gt;';
              $content= "  $table . '&lt;/table&gt;';
              mail($user-&gt;email,  "Report (". $i . ')', $content,  'Content-type: text/html');
          }
      } 
  }
  </code></pre>
  
  <p>What's wrong, how to fix it?</p>
  
  <h1>Update</h1>
  
  <p>As suggested by <em>chris</em> i've added the import parameter in config array.
  Now that issue is gone. Yet since i call for <code>Yii::app()-&gt;createAbsoluteUrl()</code> the other thing frustrates <code>Undefined index: SERVER_NAME</code>:</p>
  
  <pre><code>PHP Error[8]: Undefined index: SERVER_NAME
  in file /home/srv50213/htdocs/framework/web/CHttpRequest.php at line 317
  #0 /home/srv50213/htdocs/framework/base/CApplication.php(560): CHttpRequest-&gt;getHostInfo()
  #1 /home/srv50213/htdocs/doc/protected/commands/ReportMailerCommand.php(39): CConsoleApplication-&gt;createAbsoluteUrl()
  ...
  </code></pre>
  
  <p>What's the solution?</p>
  
  <h1>Solution</h1>
  
  <p>After some googling for createAbsoluteUrl in console command i found useful threads <a href="http://www.yiiframework.com/forum/index.php/topic/14825-problem-with-createurl-and-createabsoluteurl-in-console-application/page__view__findpost__p__117209" rel="nofollow">1</a> and <a href="https://code.google.com/p/yii/issues/detail?id=2638#c2" rel="nofollow">2</a>.</p>
  
  <p>The first gives this remedy - add following in config/console.php:</p>
  
  <pre><code>'components' =&gt; array(
       'request' =&gt; array(
          'hostInfo' =&gt; 'https://domainname.com',
          'baseUrl' =&gt; '',
          'scriptUrl' =&gt; '',
       ),
       ...
  )
  </code></pre>
  
  <p>And second way is similar:</p>
  
  <pre><code>'components' =&gt; array(
      'urlManager' =&gt; array(
          'baseUrl' =&gt; 'https://domain.com'
      )
  )
  </code></pre>