title: Set Parameter Variable Globally at all the backend Yii2
body: <p>I have this code in layout/main.php:</p>
  
  <pre><code>    $userId = Yii::$app-&gt;user-&gt;id;
      $data = User::find()-&gt;where('id ="'.$userId.'"')-&gt;one();
      $type = $data['type'];
      Yii::$app-&gt;view-&gt;params['Type'] = $type;
  </code></pre>
  
  <p>I cant' access <code>$this-&gt;params['Type']</code> from any controller except <code>SiteController</code>. If I navigated using any another controller i got this error:</p>
  
  <pre><code> PHP Notice – yii\base\ErrorException
   Undefined index: Type
  </code></pre>
  
  <p>If I duplicated my query in every controller, It works well. But I don't want to do that. How to make it globally at the <code>backend</code> only?</p>