php8.5
Home/ Manual/ yaf / yaf_session/ Yaf_Session::offsetSet

Yaf_Session::offsetSet

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Set a session value (ArrayAccess)

Description

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

Sets a session value. This method is called when array syntax is used to write to a session object.

Parameters

name

The session key to set.

value

The value to store.

Return Values

No value is returned.

Examples

Yaf_Session::offsetSet example

php
<?php
class LoginController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        // ... verify the credentials against the database
        $session = Yaf_Session::getInstance();
        $session->start();

        // writing with array syntax calls offsetSet()
        $session["user_id"] = $user->getId();
        $session["login_time"] = time();

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

See Also

  • Yaf_Session::set
  • Yaf_Session::offsetGet
  • Yaf_Session::offsetUnset

Source: reference/yaf/yaf_session/offsetset.xml · from the official PHP manual (php/doc-en)