title: yii2 gii CRUD Generator error - Class 'Message' does not exist or has syntax error
body: <p>I'm creating a basic text only private messaging system for a website using yii2 advanced.</p>
  
  <p>I'm using the gii model and CRUD generators but have encountered a problem with the CRUD generation after I have created the model class. I'm wondering whether it might be an issue with the foreign keys on the message table which have a one to many relationship with the users table (i.e. one user can have many messages).</p>
  
  <p>When I attempt to run the CRUD generator with-
  Model Class- Message
  Search Model Class - frontend\models\search\MessageSearch
  Controller Class - frontend\controllers\MessageController</p>
  
  <p>I receive the following <strong>error</strong>- </p>
  
  <blockquote>
    <p>Class 'Message' does not exist or has syntax error.</p>
  </blockquote>
  
  <p>The Message class definitely exists and 
  the syntax is
   correct according to my IDE.</p>
  
  <p>Any ideas what might be causing the error?</p>
  
  <p>The generated message class is as follows -</p>
  
  <pre><code>&lt;?php
  namespace frontend\models;
  
  use Yii;
  
  /**
  * This is the model class for table "message".
  *
  * @property integer $id
  * @property string $title
  * @property string $message
  * @property integer $from_id
  * @property integer $to_id
  * @property integer $from_viewed
  * @property integer $to_viewed
  * @property integer $from_deleted
  * @property integer $to_deleted
  * @property string $from_vdate
  * @property string $to_vdate
  * @property string $from_ddate
  * @property string $to_ddate
  * @property string $created
  *
  * @property User $to
  * @property User $from
  */
  class Message extends \yii\db\ActiveRecord
  {
  /**
   * @inheritdoc
   */
  public static function tableName()
  {
      return 'message';
  }
  
  /**
   * @inheritdoc
   */
  public function rules()
  {
      return [
          [['message', 'from_id', 'to_id', 'created'], 'required'],
          [['message'], 'string'],
          [['from_id', 'to_id', 'from_viewed', 'to_viewed', 'from_deleted', 'to_deleted'], 'integer'],
          [['from_vdate', 'to_vdate', 'from_ddate', 'to_ddate', 'created'], 'safe'],
          [['title'], 'string', 'max' =&gt; 255]
      ];
  }
  
  /**
   * @inheritdoc
   */
  public function attributeLabels()
  {
      return [
          'id' =&gt; 'ID',
          'title' =&gt; 'Title',
          'message' =&gt; 'Message',
          'from_id' =&gt; 'From ID',
          'to_id' =&gt; 'To ID',
          'from_viewed' =&gt; 'From Viewed',
          'to_viewed' =&gt; 'To Viewed',
          'from_deleted' =&gt; 'From Deleted',
          'to_deleted' =&gt; 'To Deleted',
          'from_vdate' =&gt; 'From Vdate',
          'to_vdate' =&gt; 'To Vdate',
          'from_ddate' =&gt; 'From Ddate',
          'to_ddate' =&gt; 'To Ddate',
          'created' =&gt; 'Created',
      ];
  }
  
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getTo()
  {
      return $this-&gt;hasOne(User::className(), ['id' =&gt; 'to_id']);
  }
  
  /**
   * @return \yii\db\ActiveQuery
   */
  public function getFrom()
  {
      return $this-&gt;hasOne(User::className(), ['id' =&gt; 'from_id']);
  }
  }
  </code></pre>
  
  <p>The table sql is -</p>
  
  <pre><code>--
  </code></pre>
  
  <h2>-- Table structure for table <code>message</code></h2>
  
  <p>CREATE TABLE IF NOT EXISTS <code>message</code> (
    <code>id</code> int(11) NOT NULL AUTO_INCREMENT,
    <code>title</code> varchar(255) DEFAULT NULL,
    <code>message</code> text NOT NULL,
    <code>from_id</code> int(11) NOT NULL,
    <code>to_id</code> int(11) NOT NULL,
    <code>from_viewed</code> tinyint(1) NOT NULL DEFAULT '0',
    <code>to_viewed</code> tinyint(1) NOT NULL DEFAULT '0',
    <code>from_deleted</code> tinyint(1) NOT NULL DEFAULT '0',
    <code>to_deleted</code> tinyint(1) NOT NULL DEFAULT '0',
    <code>from_vdate</code> datetime DEFAULT NULL,
    <code>to_vdate</code> datetime DEFAULT NULL,
    <code>from_ddate</code> datetime DEFAULT NULL,
    <code>to_ddate</code> datetime DEFAULT NULL,
    <code>created</code> datetime NOT NULL,
    PRIMARY KEY (<code>id</code>),
    KEY <code>from_id</code> (<code>from_id</code>),
    KEY <code>to_id</code> (<code>to_id</code>)
  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;</p>
  
  <p>--</p>
  
  <h2>-- Constraints for table <code>message</code></h2>
  
  <p>ALTER TABLE <code>message</code>
    ADD CONSTRAINT <code>message_ibfk_2</code> FOREIGN KEY (<code>to_id</code>) REFERENCES <code>user</code> (<code>id</code>),
    ADD CONSTRAINT <code>message_ibfk_1</code> FOREIGN KEY (<code>from_id</code>) REFERENCES <code>user</code> (<code>id</code>);</p>