PHP 8.6.0 Beta 3 is available for testing

Yaf_Session::offsetGet

(Yaf >=1.0.0)

Yaf_Session::offsetGet获取会话值(ArrayAccess)

说明

public function Yaf_Session::offsetGet(mixed $name): mixed

按键获取会话值。此方法是 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;
    }
}
?>

参见

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top