title: Getting Call to undefined method Yii::app() within layout view
body: <p>I've recently started using <code>Yii 2</code> and I'm having some issues with the layout file with getting the below error:</p>
  
  <pre><code>Call to undefined method Yii::app()
  </code></pre>
  
  <p>This is my layout file:</p>
  
  <pre><code>&lt;?php
  
  use yii\helpers\Html;
  
  /* @var $this yii\web\View */
  /* @var $content string */
  
  ?&gt;
  
  &lt;?php $this-&gt;beginPage() ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html lang="&lt;?=Yii::$app-&gt;language?&gt;"&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;?=Html::encode($this-&gt;title)?&gt;&lt;/title&gt;
      &lt;meta charset="&lt;?=Yii::$app-&gt;charset?&gt;"/&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;?=Html::csrfMetaTags()?&gt;
      &lt;link href="&lt;?=Yii::app()-&gt;request-&gt;baseUrl;?&gt;/css/bootstrap.min.css" rel="stylesheet" media="screen"&gt;
      &lt;link href="&lt;?=Yii::app()-&gt;request-&gt;baseUrl;?&gt;/css/custom.css" rel="stylesheet" media="screen"&gt;
  
  
  
      &lt;script type="text/javascript" src="&lt;?=Yii::app()-&gt;request-&gt;baseUrl;?&gt;/js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="&lt;?=Yii::app()-&gt;request-&gt;baseUrl;?&gt;/js/scripts.js"&gt;&lt;/script&gt;
  
      &lt;!--[if lte IE 8]&gt;
          &lt;script src="&lt;?=Yii::app()-&gt;request-&gt;baseUrl;?&gt;/js/html5shiv.min.js"&gt;&lt;/script&gt;
          &lt;script src="&lt;?=Yii::app()-&gt;request-&gt;baseUrl;?&gt;/js/respond.min.js"&gt;&lt;/script&gt;
      &lt;![endif]--&gt;
  
      &lt;?php $this-&gt;head() ?&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;?php $this-&gt;beginBody() ?&gt;
  
  &lt;?=$content?&gt;
  
  &lt;?php $this-&gt;endBody() ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;?php $this-&gt;endPage() ?&gt;
  </code></pre>
  
  <p>When I use <code>Yii::$app</code> I get no issues, but if I use <code>Yii::app()</code> then I get that error.</p>
  
  <p>I started using <code>Yii::app()</code> in some places as I was reading around and was told you should use the below to make sure to include <em>absolute</em> path names within views:</p>
  
  <pre><code>Yii::app()-&gt;request-&gt;baseUrl
  </code></pre>
  
  <p>...and to include jQuery use:</p>
  
  <pre><code>Yii::app()-&gt;clientScript-&gt;registerCoreScript("jquery");
  </code></pre>
  
  <p>However when I do anything with <code>app()</code> I get the above error.</p>
  
  <p>I tried replacing <code>app()</code> with <code>$app</code>; the page loaded fine but there was a blank value in <code>Yii::$app-&gt;request-&gt;baseUrl</code>.</p>
  
  <p>What am I doing wrong here!?</p>