Yaf_Session::get
(Yaf >=1.0.0)
Yaf_Session::get — 获取会话值
说明
按名字获取会话值。如果省略 name 或其值为 null,则返回整个会话数组。
示例
示例 #1 Yaf_Session::get() 示例
<?php
class ProfileController extends Yaf_Controller_Abstract
{
public function indexAction()
{
$session = Yaf_Session::getInstance();
$session->start();
$userId = $session->get("user_id");
if ($userId === null) {
return $this->redirect("/account/login");
}
echo "welcome back, user #", $userId;
}
}
?>参见
- Yaf_Session::set() - 设置会话值
- Yaf_Session::has() - 检查会话键是否存在
- Yaf_Session::del() - 删除会话键
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
