Documentation

SessionModel
in package
implements SessionModelInterface

AbstractYes

Abstract session management model.

Provides a standardized interface for storing and retrieving user session data. Extend this class and implement getUser() to define custom user data retrieval.

Usage:

class UserSession extends \X\Model\SessionModel {
  protected static function getUser(string $id): array {
    return (new UserModel())->get_by_id((int)$id);
  }
}

// Set user session
UserSession::set($userId);

// Get session data
$user = UserSession::get();

Table of Contents

Interfaces

SessionModelInterface
Interface for session management models.

Constants

SESSION_NAME  = 'user'
Key name of the session to store user information.

Methods

get()  : stdClass|string
Get session.
isset()  : bool
Isset session.
set()  : string
Set session.
unset()  : string
Session discarded.
getUser()  : array<string|int, mixed>
Callback set session.

Constants

SESSION_NAME

Key name of the session to store user information.

public string SESSION_NAME = 'user'

Methods

get()

Get session.

public final static get([string $field = null ]) : stdClass|string
Parameters
$field : string = null

(optional) If you want to retrieve only a specific field from the session, specify the name of that field.

Return values
stdClass|string

Session data.

isset()

Isset session.

public final static isset() : bool
Return values
bool

Whether the session exists.

set()

Set session.

public final static set(string $id[, mixed $value = null ]) : string
Parameters
$id : string

It is ID if there is only one argument, column name if there are two arguments.

$value : mixed = null

Set value.

Return values
string

Subclass Name.

unset()

Session discarded.

public final static unset() : string
Return values
string

Subclass Name.

getUser()

Callback set session.

protected abstract static getUser(string $id) : array<string|int, mixed>
Parameters
$id : string

User ID.

Return values
array<string|int, mixed>

User data.


        
On this page

Search results