(Yaf >=1.0.0)
Yaf_Session::offsetGet — 获取会话值(ArrayAccess)
按键获取会话值。此方法是 Yaf_Session::get() 的别名,在以数组方式读取会话对象时会被调用。
name要获取的会话键。
会话值,键不存在时返回 null。
示例 #1 Yaf_Session::offsetGet() 示例
<?php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction()
{
$session = Yaf_Session::getInstance();
$session->start();
// 以数组方式读取时会调用 offsetGet()
$userId = $session["user_id"];
if ($userId === null) {
return $this->redirect("/account/login");
}
echo "logged in as user #", $userId;
}
}
?>