(Yaf >=1.0.0)
Yaf_Session::get — 获取会话值
按名字获取会话值。如果省略 name 或其值为 null,则返回整个会话数组。
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;
}
}
?>