Yaf_Session::offsetGet
PHP function
Edit on GitHub ✎
(Yaf >=1.0.0)
Get a session value (ArrayAccess)
Description
Yaf_Session::offsetGet(mixed $name): mixed
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
nameThe session key to retrieve.
Return Values
The session value, or null if the key does not exist.
Examples
Yaf_Session::offsetGet example
php
<?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::getYaf_Session::offsetSetYaf_Session::offsetUnset