title: Yii 2: Session Variable Disappearing
body: <p>I have a controller in Yii 2.0 wherein I save session variables.</p>
  
  <pre><code>$session = Yii:$app-&gt;session;
  $session-&gt;open();
  $session['user_id'] = $userId;
  </code></pre>
  
  <p>When I try to access the session variable from another class which does not extend the Yii 2 Controller class(if I display it in the original class though, the value is there), the variable has no value. </p>
  
  <pre><code>$session = Yii::$app-&gt;session;
  $session-&gt;open();
  
  echo $session['user_id'];
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Here is a snippet from the model class where I'm using the session variable:</p>
  
  <pre><code> public function create()
  {
      $session = Yii::$app-&gt;session;
      ...
      $model-&gt;user_id = ''.$session['user_id'];
      ...
  
      $model-&gt;save(FALSE);
  
  }
  </code></pre>