phpday 2027 - Call for Papers

Yaf_Session::get

(Yaf >=1.0.0)

Yaf_Session::get — Get a session value

Description

public function Yaf_Session::get(string $name = NULL): mixed

Retrieves a session value by name. If name is omitted or null, the entire session array is returned.

Parameters

name

The session key to retrieve, or null to get all session data.

Return Values

The session value, or null if the key does not exist. When name is null, the full session array is returned.

Examples

Example #1 Yaf_Session::get() example

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

        $userId = $session->get("user_id");
        if ($userId === null) {
            return $this->redirect("/account/login");
        }

        echo "welcome back, user #", $userId;
    }
}
?>

See Also

User Contributed Notes

There are no user contributed notes for this page.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top