Yaf_Session::offsetGet

Get a session value (ArrayAccess)

Description

public mixed Yaf_Session::offsetGet(mixed $name)

Retrieves a session value by key. This method is an alias of Yaf_Session::get and is called when array syntax is used to read a session object.

Parameters

name
The session key to retrieve.

Return Values

The session value, or null if the key does not exist.

Examples

Example #1 Yaf_Session::offsetGet example

<?php
class IndexController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        $session = Yaf_Session::getInstance();
        $session->start();

        // reading with array syntax calls offsetGet()
        $userId = $session["user_id"];
        if ($userId === null) {
            return $this->redirect("/account/login");
        }

        echo "logged in as user #", $userId;
    }
}
?>

See Also

  • Yaf_Session::get
  • Yaf_Session::offsetSet
  • Yaf_Session::offsetUnset