Session
API reference › PSR bridge › http › Session
Keeps native session shutdown and flash aging bounded to the worker request lifecycle.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$allFlashes read-only | array | Flash messages (key => message or key => [message1, message2]). | yii\ |
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$cacheLimiter | string | Current cache limiter. | yii\ |
$cookieParams | array | The session cookie parameters. | yii\ |
$count read-only | int | The number of session variables. | yii\ |
$flash write-only | string | The key identifying the flash message. | yii\ |
$flashParam | string | The name of the session variable that stores the flash message data. Default: '__flash'. | yii\ |
$gCProbability | float | The probability (percentage) that the GC (garbage collection) process is started on every session initialization. | yii\ |
$handler | SessionHandlerInterface| | An object implementing the SessionHandlerInterface or a configuration array. Default: null. | yii\ |
$hasSessionId | bool | Whether the current request has sent the session ID. | yii\ |
$id | string | The current session ID. | yii\ |
$isActive read-only | bool | Whether the session has started. | yii\ |
$iterator read-only | yii\ | An iterator for traversing the session variables. | yii\ |
$name | string | The current session name. | yii\ |
$savePath | string | The current session save path, defaults to ‘/tmp’. | yii\ |
$timeout | int | The number of seconds after which data will be seen as ‘garbage’ and cleaned up. | yii\ |
$useCookies | bool| | The value indicating whether cookies should be used to store session IDs. | yii\ |
$useCustomStorage read-only | bool | Whether to use custom storage. | yii\ |
$useStrictMode | bool | Whether strict mode is enabled or not. | yii\ |
$useTransparentSessionID | bool | Whether transparent sid support is enabled or not, defaults to false. | yii\ |
$_forceRegenerateId protected | string| | Holds the session id in case useStrictMode is enabled and the session id needs to be regenerated Default: null. | yii\ |
$_originalSessionModule protected static | string| | Holds the original session module (before a custom handler is registered) so that it can be restored when a Session component without custom handler is used after one that has. Default: null. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
addFlash() | Adds a flash message. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
close() | Ends the current session and store session data. | yii\ |
count() | Returns the number of items in the session. | yii\ |
destroy() | Frees all session variables and destroys all data registered to a session. | yii\ |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
get() | Returns the session variable value with the session variable name. | yii\ |
getAllFlashes() | Returns all flash messages. | yii\ |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
getCacheLimiter() | Returns current cache limiter | yii\ |
getCookieParams() | yii\ | |
getCount() | Returns the number of items in the session. | yii\ |
getFlash() | Returns a flash message. | yii\ |
getGCProbability() | yii\ | |
getHasSessionId() | Returns a value indicating whether the current request has sent the session ID. | yii\ |
getId() | Gets the session ID. | yii\ |
getIsActive() | yii\ | |
getIterator() | Returns an iterator for traversing the session variables. | yii\ |
getName() | Gets the name of the current session. | yii\ |
getSavePath() | Gets the current session save path. | yii\ |
getTimeout() | yii\ | |
getUseCookies() | Returns the value indicating whether cookies should be used to store session IDs. | yii\ |
getUseCustomStorage() | Returns a value indicating whether to use custom session storage. | yii\ |
getUseStrictMode() | yii\ | |
getUseTransparentSessionID() | yii\ | |
has() | yii\ | |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasFlash() | Returns a value indicating whether there are flash messages associated with the specified key. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
init() | Replaces Yii’s per-instance shutdown callback with one weak process dispatcher. | Session |
off() | Detaches an existing event handler from this component. | yii\ |
offsetExists() | This method is required by the interface ArrayAccess. | yii\ |
offsetGet() | This method is required by the interface ArrayAccess. | yii\ |
offsetSet() | This method is required by the interface ArrayAccess. | yii\ |
offsetUnset() | This method is required by the interface ArrayAccess. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
open() | Starts the session. | yii\ |
regenerateID() | Updates the current session ID with a newly generated one. | yii\ |
remove() | Removes a session variable. | yii\ |
removeAll() | Removes all session variables. | yii\ |
removeAllFlashes() | Removes all flash messages. | yii\ |
removeFlash() | Removes a flash message. | yii\ |
set() | Adds a session variable. | yii\ |
setCacheLimiter() | Set cache limiter | yii\ |
setCookieParams() | Sets the session cookie parameters. | yii\ |
setFlash() | Sets a flash message. | yii\ |
setGCProbability() | yii\ | |
setHasSessionId() | Sets the value indicating whether the current request has sent the session ID. | yii\ |
setId() | Sets the session ID. | yii\ |
setName() | Sets the name for the current session. | yii\ |
setSavePath() | Sets the current session save path. | yii\ |
setTimeout() | yii\ | |
setUseCookies() | Sets the value indicating whether cookies should be used to store session IDs. | yii\ |
setUseStrictMode() | yii\ | |
setUseTransparentSessionID() | yii\ | |
trigger() | Triggers an event. | yii\ |
freeze() protected | If session is started it’s not possible to edit session ini settings. In PHP7.2+ it throws exception. | yii\ |
registerSessionHandler() protected | Registers session handler. | yii\ |
unfreeze() protected | Starts session and restores data from temporary variable | yii\ |
updateFlashCounters() protected | Ages flash values once even when bootstrap and the action reopen the session. | Session |
Method details
Section titled “Method details”init()
Section titled “init() ”public function init(): mixedReplaces Yii’s per-instance shutdown callback with one weak process dispatcher.
Returns
mixed
updateFlashCounters()
Section titled “updateFlashCounters() ”protected function updateFlashCounters(): mixedAges flash values once even when bootstrap and the action reopen the session.
Returns
mixed