title: Yii2 - check if the user is logged in view
body: <p>I am trying to check is the user logged inside my view file, but I keep getting this error:</p>
  
  <pre><code>Call to undefined method Yii::app()
  </code></pre>
  
  <p>I tried adding <strong>$</strong> before <strong>app</strong> but the error is still there (this time it is <strong>Undefined variable: app</strong>). Is it possible to this is view?</p>
  
  <p>This is the code I use the check if the user is logged:</p>
  
  <pre><code>&lt;?php
          if(Yii::app()-&gt;isGuest)
              echo 'User is not logged!';
      ?&gt;
  </code></pre>