PHP 8.6.0 Beta 3 is available for testing

Yaf_Session::offsetSet

(Yaf >=1.0.0)

Yaf_Session::offsetSet设置会话值(ArrayAccess)

说明

public function Yaf_Session::offsetSet(mixed $name, mixed $value): void

设置一个会话值。当使用数组语法写入会话对象时,会调用此方法。

参数

name

要设置的会话键。

value

要存储的值。

返回值

没有返回值。

示例

示例 #1 Yaf_Session::offsetSet() 示例

<?php
class LoginController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        // ... 根据数据库验证用户凭证
        $session = Yaf_Session::getInstance();
        $session->start();

        // 使用数组语法写入会调用 offsetSet()
        $session["user_id"] = $user->getId();
        $session["login_time"] = time();

        return $this->redirect("/dashboard");
    }
}
?>

参见

添加备注

用户贡献的备注

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