【发布时间】:2015-10-22 02:53:25
【问题描述】:
我正在使用Yii2,我刚刚开始在其中使用sessions。我已经在 Yii 网站上为他们阅读了documentation。
我注意到的一件事是,如果不使用标准的超全局 $_SESSION,在会话中处理多维数组有点困难,因此我主要使用它。
但我遇到的一件事是取消设置会话变量。
例子:
if (!Yii::$app->session->isActive) {
Yii::$app->session->open();
}
print_r($_SESSION['foo']);
if ($this->command == 'sample_action') {
if (!isset($_SESSION['foo'][$this->some_id][$this->example_id])) {
$_SESSION['foo'][$this->some_id][$this->example_id] = $this->example_id;
$result = true;
}
} elseif ($this->command == 'sample_action_2') {
if (isset($_SESSION['foo'][$this->some_id][$this->example_id])) {
unset($_SESSION['foo'][$this->some_id][$this->example_id]);
//$_SESSION['foo'][$this->some_id][$this->example_id] = ''; // This works
$result = true;
}
}
print_r($_SESSION['foo']);
在它上面使用unset 根本不起作用,它仍然存在。但是,将其设置为空白值是可行的。
【问题讨论】:
标签: php session yii yii2 unset