title: Yii2 error: The view file does not exist
body: <p>I've been using Yii2 for a few weeks now, and getting the hang of it. However, today, for a reason I do not know, Yii's been routing me to the wrong page, causing errors because web pages have not been found:</p>
  
  <pre><code>URL: 
  http://localhost/web/index.php?r=site/index
  
  Error:
  Invalid Parameter – yii\base\InvalidParamException
  The view file does not exist: C:\xampp\htdocs\views\site\index.php
  </code></pre>
  
  <p>However, I've been able to navigate my site with <code>http://localhost/web/index.php?r=paramA/paramB</code> since I started using Yii2, and I haven't been editing configuration files for quite some time, so I don't know why this started happening.</p>
  
  <p>A few files which might be useful:</p>
  
  <p><code>/web/index.php</code> (barely edited): </p>
  
  <pre><code>&lt;?php
  
  require_once __DIR__.'/../util/Tools.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();
  </code></pre>
  
  <p>part of <code>controllers/SiteController.php</code>:</p>
  
  <pre><code>public function actions()
  {
      return [
          'error' =&gt; [
              'class' =&gt; 'yii\web\ErrorAction',
          ],
          ...
      ];
  }
  
  public function actionIndex()
  {
      return $this-&gt;render('index');
  }
  </code></pre>
  
  <p>Also, in <code>config/web.php</code> I have no <code>urlManager</code> component.</p>
  
  <p><strong>Why is this happening and what can I do against it?</strong> Also, since I do not know where to search, I probably haven't posted the correct code to analyze, but of course I can add code when necessary.</p>
  
  <p>Moreover, it started when I started throwing some <code>UserExceptions</code> (To show some invalid post requests and such). That instantly showed an error that <code>/views/site/error.php</code> did not exist. I created that php file, but then the problem described above occurred. I removed the <code>/views/site/error.php</code> file, but the problem persists.</p>
  
  <p>I guess it has something to do with url rewriting, but nothing happened after adding an <code>urlManager</code> component to <code>/config/web.php</code> (which I removed after trying)</p>
  
  <p>Also, in <code>\vendor\yiisoft\yii2\base\View.php</code> there's this code:</p>
  
  <pre><code>public function render($view, $params = [], $context = null)
  {
      $viewFile = $this-&gt;findViewFile($view, $context);   
      return $this-&gt;renderFile($viewFile, $params, $context);
  }
  </code></pre>
  
  <p>And <code>$viewFile</code> returns the path which can't be found (<code>views\site\index.php</code>). </p>
  
  <p>Also, in <code>SiteController.php</code>, <code>$this-&gt;viewPath</code> is <code>C:\xampp\htdocs\views\site</code> (which it shouldn't..?)</p>
  
  <p>The stack trace:</p>
  
  <pre><code>1. in C:\xampp\htdocs\vendor\yiisoft\yii2\base\View.php at line 226
  2. in C:\xampp\htdocs\vendor\yiisoft\yii2\base\View.php at line 149 – yii\base\View::renderFile('C:\xampp\htdocs\...', [], app\controllers\SiteController)
  3. in C:\xampp\htdocs\vendor\yiisoft\yii2\base\Controller.php at line 371 – yii\base\View::render('index', [], app\controllers\SiteController)
  4. in C:\xampp\htdocs\controllers\SiteController.php at line 58 – yii\base\Controller::render('index')
  5. app\controllers\SiteController::actionIndex()
  6. in C:\xampp\htdocs\vendor\yiisoft\yii2\base\InlineAction.php at line 55 – call_user_func_array([app\controllers\SiteController, 'actionIndex'], [])
  7. in C:\xampp\htdocs\vendor\yiisoft\yii2\base\Controller.php at line 151 – yii\base\InlineAction::runWithParams(['r' =&gt; 'site/index'])
  8. in C:\xampp\htdocs\vendor\yiisoft\yii2\base\Module.php at line 455 – yii\base\Controller::runAction('index', ['r' =&gt; 'site/index'])
  9. in C:\xampp\htdocs\vendor\yiisoft\yii2\web\Application.php at line 84 – yii\base\Module::runAction('site/index', ['r' =&gt; 'site/index'])
  10. in C:\xampp\htdocs\vendor\yiisoft\yii2\base\Application.php at line 375 – yii\web\Application::handleRequest(yii\web\Request)
  11. in C:\xampp\htdocs\web\index.php at line 16 – yii\base\Application::run()
  </code></pre>
  
  <p>Edit: </p>
  
  <p>as you might have seen by now, my <code>DOCUMENT_ROOT</code> is <code>C:\xampp\htdocs</code>, and I am using the basic template</p>
  
  <p>Edit2: </p>
  
  <p>config/web.php</p>
  
  <pre><code>&lt;?php
  
  defined('DOCUMENT_ROOT') or define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT']."/");
  
  require_once DOCUMENT_ROOT . "/util/Tools.php";
  $params = require(__DIR__ . '/params.php');
  
  $config = [
      "modules" =&gt; [
          "gridview" =&gt; [
              "class" =&gt; '\kartik\grid\Module'
          ]
      ],
      'id' =&gt; 'basic',
      'basePath' =&gt; dirname(__DIR__),
      'bootstrap' =&gt; ['log'],
      'components' =&gt; [
          'request' =&gt; [
              // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
              'cookieValidationKey' =&gt; 'SOMERANDOMSTRING',
          ],
          'cache' =&gt; [
              'class' =&gt; 'yii\caching\FileCache',
          ],
          'user' =&gt; [
              'identityClass' =&gt; 'app\models\User',
              'enableAutoLogin' =&gt; true,
          ],
          'errorHandler' =&gt; [
              'errorAction' =&gt; 'site/error',
          ],
          'mailer' =&gt; [
              'class' =&gt; 'yii\swiftmailer\Mailer',
              // send all mails to a file by default. You have to set
              // 'useFileTransport' to false and configure a transport
              // for the mailer to send real emails.
              'useFileTransport' =&gt; true,
          ],
          'log' =&gt; [
              'traceLevel' =&gt; YII_DEBUG ? 3 : 0,
              'targets' =&gt; [
                  [
                      'class' =&gt; 'yii\log\FileTarget',
                      'levels' =&gt; ['error', 'warning'],
                  ],
              ],
          ],
          'db' =&gt; require(__DIR__ . '/db.php'),
          'authManager' =&gt; [
              'class' =&gt; 'app\components\MyPhpManager',
          ],
      ],
      'params' =&gt; $params,
  ];
  
  if (YII_ENV_DEV) {
      // configuration adjustments for 'dev' environment
      $config['bootstrap'][] = 'debug';
      $config['modules']['debug'] = [
          'class' =&gt; 'yii\debug\Module',
      ];
  
      $config['bootstrap'][] = 'gii';
      $config['modules']['gii'] = [
          'class' =&gt; 'yii\gii\Module',
      ];
  }
  
  return $config;
  </code></pre>
  
  <p>controllers\SiteController.php</p>
  
  <pre><code>&lt;?php
  
  namespace app\controllers;
  
  use Yii;
  use yii\filters\AccessControl;
  use yii\web\Controller;
  use yii\filters\VerbFilter;
  use app\models\LoginForm;
  use app\models\ContactForm;
  use app\models\UploadForm;
  use app\models\User;
  use app\models\Document;
  use app\components\XmlParser;
  
  class SiteController extends Controller
  {
      public function behaviors()
      {
          return [
              'access' =&gt; [
                  'class' =&gt; AccessControl::className(),
                  'only' =&gt; ['logout'],
                  'rules' =&gt; [
                      [
                          'actions' =&gt; ['logout'],
                          'allow' =&gt; true,
                          'roles' =&gt; ['@'],
                      ],
                  ],
              ],
              'verbs' =&gt; [
                  'class' =&gt; VerbFilter::className(),
                  'actions' =&gt; [
                      'logout' =&gt; ['post'],
                      'upload'=&gt;['post'],
                      'assign'=&gt;['post'],
                  ],
              ],
          ];
      }
  
      public function actions()
      {
          return [
              'error' =&gt; [
                  'class' =&gt; 'yii\web\ErrorAction',
              ],
              'captcha' =&gt; [
                  'class' =&gt; 'yii\captcha\CaptchaAction',
                  'fixedVerifyCode' =&gt; YII_ENV_TEST ? 'testme' : null,
              ],
          ];
      }
  
      public function actionIndex()
      {
          return $this-&gt;render('index');
      }
  
      public function actionLogin()
      {
          if (!Yii::$app-&gt;user-&gt;isGuest) {
              return $this-&gt;goHome();
          }
  
          $model = new LoginForm();
          if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;login()) {
              return $this-&gt;goBack();
          }
          return $this-&gt;render('login', [
              'model' =&gt; $model,
          ]);
      }
  
      public function actionLogout()
      {
          Yii::$app-&gt;user-&gt;logout();
  
          return $this-&gt;goHome();
      }
  
      public function actionContact()
      {
          $model = new ContactForm();
          if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;contact(Yii::$app-&gt;params['adminEmail'])) {
              Yii::$app-&gt;session-&gt;setFlash('contactFormSubmitted');
  
              return $this-&gt;refresh();
          }
          return $this-&gt;render('contact', [
              'model' =&gt; $model,
          ]);
      }
  
      public function actionAbout()
      {
          return $this-&gt;render('about');
      }
  
      public function actionAssign() {
          //custom method
      }
  
      public function actionUpload()
      {       
          //custom method
      }
  
      public function beforeAction($action) {           
          Yii::$app-&gt;controller-&gt;enableCsrfValidation = !($action-&gt;id == 'upload');
  
          return parent::beforeAction($action);
      }
  }
  </code></pre>