Yaf_Session::get

(Yaf >=1.0.0)

Yaf_Session::getGet a session value

Опис

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.

Параметри

name

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

Значення, що повертаються

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

Приклади

Приклад #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;
    }
}
?>

Прогляньте також

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top