[英]Yii2. Pjax and Session
For testing reasons, I am trying to use Pjax in a widget. 出于测试原因,我试图在小部件中使用Pjax。 In the view: 在视图中:
$testArgs = [
'param' => 'test'
];
Yii::$app->session->set('testArgs', $testArgs);
echo Test::widget($testArgs);
Then in the widget: 然后在小部件中:
class Test extends Widget {
public $param;
..
public function init() {
..
}
public function run() {
Pjax::begin();
echo "<a href='test/add'>[ + ]</a> | <a href='test/remove'>[ - ]</a>";
Pjax::end();
}
}
Then in TestController: 然后在TestController中:
public function actionAdd() {
$testArgs = Yii::$app->session->get('testArgs');
var_dump($testArgs);
die;
}
$testArgs is NULL. $ testArgs为NULL。 Why? 为什么? Pjax creates a different session? Pjax创建另一个会话?
UPDATE 1 更新1
I have added an echo with session_id() and it seems is same session 我用session_id()添加了回显,似乎是同一会话
UPDATE 2 更新2
In the real widget I am passing to session a $form (ActiveForm) object. 在实际的小部件中,我将传递给$ form(ActiveForm)对象进行会话。 I think this is the issue. 我认为这是问题所在。 I tried to serialize it, but it returned an error saying "Closure can not be serialized" 我试图对其进行序列化,但是它返回一个错误,提示“无法序列化关闭”
UPDATE 3 更新3
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. 由于我无法从对象中删除闭包,因此闭包序列化似乎是PHP在审查如何绕过闭包时众所周知的错误。
I will answer this question. 我会回答这个问题。 No, PJax does not create a different session. 不,PJax不会创建其他会话。 Adding form object to my session is breaking it, I will open a different question for this. 将表单对象添加到我的会话中会破坏它,为此我将打开一个不同的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.