Craft 3 Class Reference

Class craft\behaviors\SessionBehavior

Inheritance
craft\behaviors\SessionBehavior » yii\base\Behavior » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/behaviors/SessionBehavior.php

Extends \yii\web\Session to add support for setting the session folder and creating it if it doesn’t exist.

Public Properties
Property Type Description Defined By
$assetBundleFlashKey string The name of the flash key that stores asset bundle data craft\behaviors\SessionBehavior
$authAccessParam string, null The session variable name used to store the authorization keys for the current session. craft\behaviors\SessionBehavior
$jsFlashKey string The name of the flash key that stores JS data craft\behaviors\SessionBehavior
$owner yii\base\Component, null The owner of this behavior yii\base\Behavior
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
addAssetBundleFlash() Queues up an asset bundle to be registered on a future request. craft\behaviors\SessionBehavior
addJsFlash() Stores JS in the user’s flash data. craft\behaviors\SessionBehavior
attach() Attaches the behavior object to the component. yii\base\Behavior
authorize() Authorizes the user to perform an action for the duration of the session. craft\behaviors\SessionBehavior
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
checkAuthorization() Returns whether the user is authorized to perform an action. craft\behaviors\SessionBehavior
className() Returns the fully qualified name of this class. yii\base\BaseObject
deauthorize() Deauthorizes the user from performing an action. craft\behaviors\SessionBehavior
detach() Detaches the behavior object from the component. yii\base\Behavior
events() Declares event handlers for the $owner's events. yii\base\Behavior
getAssetBundleFlashes() Returns the list of queued-up asset bundles in the session flash data. craft\behaviors\SessionBehavior
getJsFlashes() Returns the stored JS flashes. craft\behaviors\SessionBehavior
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject
setError() Stores an error message in the user’s flash data. craft\behaviors\SessionBehavior
setNotice() Stores a notice in the user’s flash data. craft\behaviors\SessionBehavior

Property Details

$assetBundleFlashKey public property #

The name of the flash key that stores asset bundle data

public string $assetBundleFlashKey '__ab'

$authAccessParam public property #

The session variable name used to store the authorization keys for the current session.

See also:

public string, null $authAccessParam null

$jsFlashKey public property #

The name of the flash key that stores JS data

public string $jsFlashKey '__js'

Method Details

addAssetBundleFlash() public method #

Queues up an asset bundle to be registered on a future request.

Asset bundles that were queued with this method can be registered using getAssetBundleFlashes() or craft\web\View::getBodyHtml().

See also getAssetBundleFlashes().

public void addAssetBundleFlash ( \craft\behaviors\string $name, \craft\behaviors\int $position null )
$name string The class name of the asset bundle (without the leading backslash)
$position integer, null If set, this forces a minimum position for javascript files.
throws yii\base\Exception if $name isn't an asset bundle class name

addJsFlash() public method #

Stores JS in the user’s flash data.

The JavaScript code will be stored on the session, and can be retrieved by calling getJsFlashes() or craft\web\View::getBodyHtml().

See also:

public void addJsFlash ( \craft\behaviors\string $js, \craft\behaviors\int $position = \craft\web\View::POS_READY, \craft\behaviors\string $key null )
$js string The JS code block to be registered
$position integer The position at which the JS script tag should be inserted in a page.
$key string, null The key that identifies the JS code block.

authorize() public method #

Authorizes the user to perform an action for the duration of the session.

public void authorize ( \craft\behaviors\string $action )
$action string

checkAuthorization() public method #

Returns whether the user is authorized to perform an action.

public boolean checkAuthorization ( \craft\behaviors\string $action )
$action string

deauthorize() public method #

Deauthorizes the user from performing an action.

public void deauthorize ( \craft\behaviors\string $action )
$action string

getAssetBundleFlashes() public method #

Returns the list of queued-up asset bundles in the session flash data.

See also addAssetBundleFlash().

public array getAssetBundleFlashes ( \craft\behaviors\bool $delete false )
$delete boolean Whether to delete the stored flashes. Defaults to true.
return array The queued-up asset bundles.

getJsFlashes() public method #

Returns the stored JS flashes.

See also addJsFlash().

public array getJsFlashes ( \craft\behaviors\bool $delete true )
$delete boolean Whether to delete the stored flashes. Defaults to true.
return array The stored JS flashes.

setError() public method #

Stores an error message in the user’s flash data.

The message will be stored on the session, and can be retrieved by calling \craft\behaviors\getFlash() or \craft\behaviors\getAllFlashes(). Only one flash error message can be stored at a time.

public void setError ( \craft\behaviors\string $message )
$message string The message.

setNotice() public method #

Stores a notice in the user’s flash data.

The message will be stored on the session, and can be retrieved by calling \craft\behaviors\getFlash() or \craft\behaviors\getAllFlashes(). Only one flash notice can be stored at a time.

public void setNotice ( \craft\behaviors\string $message )
$message string The message.