title: Yii2. Invalid path alias
body: <p>I've seen similiar questions but haven't found a working solution. Here is my index.php file:</p>
  
  <pre><code>&lt;?php
  
  // comment out the following two lines when deployed to production
  defined('YII_DEBUG') or define('YII_DEBUG', true);
  defined('YII_ENV') or define('YII_ENV', 'dev');
  
  require(__DIR__ . '/../vendor/autoload.php');
  require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
  
  $config = require(__DIR__ . '/../config/web.php');
  
  (new yii\web\Application($config))-&gt;run();
  
  require(__DIR__ . '/../config/aliases.php');
  </code></pre>
  
  <p>As you can see, it requires <code>config/aliases.php</code> file, whose contents are:</p>
  
  <pre><code>&lt;?php
  
  Yii::setAlias('message_files_root', '@webroot/message_files');
  Yii::setAlias('message_files', '@web/message_files');
  </code></pre>
  
  <p>Calling<code>Yii::getAlias('@message_files_root')</code> works fine within the <code>index.php</code>, but when it is in a controller file, it says <code>Invalid path alias: @message_files_root</code>.</p>
  
  <p>Here is my controller's action (the rest of the code is fully commented):</p>
  
  <pre><code>public function actionIndex()
  {
      var_dump(Yii::getAlias('@message_files_root'));
  
      $message = new Message();
  </code></pre>