title: Yii2. Pjax and Session
body: <p>For testing reasons, I am trying to use Pjax in a widget. In the view:</p>
  
  <pre><code>$testArgs = [
              'param' =&gt; 'test'
          ];
  Yii::$app-&gt;session-&gt;set('testArgs', $testArgs);
  echo Test::widget($testArgs);
  </code></pre>
  
  <p>Then in the widget:</p>
  
  <pre><code>class Test extends Widget {
  
      public $param;
      ..
  
      public function init() {
        ..
      }
  
      public function run() {
  
          Pjax::begin();
  
          echo "&lt;a href='test/add'&gt;[ + ]&lt;/a&gt; | &lt;a href='test/remove'&gt;[ - ]&lt;/a&gt;";
  
          Pjax::end();
      }
  }
  </code></pre>
  
  <p>Then in TestController:</p>
  
  <pre><code>public function actionAdd() {
     $testArgs = Yii::$app-&gt;session-&gt;get('testArgs');
     var_dump($testArgs);
     die;
   }
  </code></pre>
  
  <p>$testArgs is NULL. Why? Pjax creates a different session?   </p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>I have added an echo with session_id() and it seems is same session</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>In the real widget I am passing to session a $form (ActiveForm) object. I think this is the issue. I tried to serialize it, but it returned an error saying "Closure can not be serialized"</p>
  
  <p><strong>UPDATE 3</strong></p>
  
  <p>It seems that closure serialization is a well known error in PHP reviewing how to by pass that, since I can not remove the closures from the object.</p>