yii2 session
开启和关闭Sessions
$session = Yii::$app->session;
// 检查session是否开启
if ($session->isActive) ...
// 开启session
$session->open();
// 关闭session
$session->close();
// 销毁session中所有已注册的数据
$session->destroy();
访问Session数据
$session = Yii::$app->session;
// 获取session中的变量值,以下用法是相同的:
$language = $session->get('language');
$language = $session['language'];
$language = isset($_SESSION['language']) ? $_SESSION['language'] : null;
// 设置一个session变量,以下用法是相同的:
$session->set('language', 'en-US');
$session['language'] = 'en-US';
$_SESSION['language'] = 'en-US';
// 删除一个session变量,以下用法是相同的:
$session->remove('language');
unset($session['language']);
unset($_SESSION['language']);
// 检查session变量是否已存在,以下用法是相同的:
if ($session->has('language')) ...
if (isset($session['language'])) ...
if (isset($_SESSION['language'])) ...
// 遍历所有session变量,以下用法是相同的:
foreach ($session as $name => $value) ...
foreach ($_SESSION as $name => $value) ...
标签:session,...,en,language,用法,SESSION,yii2
From: https://www.cnblogs.com/hu308830232/p/18105500