Skip to content

SessionBehavior ​

Type
Class
Namespace
craft\behaviors
Inherits
craft\behaviors\SessionBehavior » yii\base\Behavior » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0.0

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

View source

Public Properties ​

PropertyDescription
assetBundleFlashKeystring – The name of the flash key that stores asset bundle data
assetBundleFlashesarray – The queued-up asset bundles.
authAccessParamstring, null – The session variable name used to store the authorization keys for the current session.
errorstring – The message.
jsFlashKeystring – The name of the flash key that stores JS data
jsFlashesarray – The stored JS flashes.
noticestring – The message.
ownercraft\web\Session

assetBundleFlashKey ​

Type
string
Default value
'__ab'

The name of the flash key that stores asset bundle data

View source

assetBundleFlashes ​

Type
array
Default value
null
Access
Read-only

The queued-up asset bundles.

View source

authAccessParam ​

Type
string, null
Default value
null

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

See also:

View source

error ​

Type
string
Default value
null
Access
Write-only

The message.

View source

jsFlashKey ​

Type
string
Default value
'__js'

The name of the flash key that stores JS data

View source

jsFlashes ​

Type
array
Default value
null
Access
Read-only

The stored JS flashes.

View source

notice ​

Type
string
Default value
null
Access
Write-only

The message.

View source

owner ​

Type
craft\web\Session
Default value
null

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
addAssetBundleFlash()Queues up an asset bundle to be registered on a future request.
addJsFlash()Stores JS in the user’s flash data.
attach()Attaches the behavior object to the component.
authorize()Authorizes the user to perform an action for the duration of the session.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
checkAuthorization()Returns whether the user is authorized to perform an action.
className()Returns the fully qualified name of this class.
deauthorize()Deauthorizes the user from performing an action.
detach()Detaches the behavior object from the component.
events()Declares event handlers for the owner's events.
getAssetBundleFlashes()Returns the list of queued-up asset bundles in the session flash data.
getJsFlashes()Returns the stored JS flashes.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
setError()Stores an error message in the user’s flash data.
setNotice()Stores a notice in the user’s flash data.

addAssetBundleFlash() ​

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()View source

Arguments ​

  • $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 ​

addJsFlash() ​

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:

View source

Arguments ​

  • $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() ​

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

View source

Arguments ​

checkAuthorization() ​

Returns whether the user is authorized to perform an action.

View source

Arguments ​

Returns ​

boolean

deauthorize() ​

Deauthorizes the user from performing an action.

View source

Arguments ​

getAssetBundleFlashes() ​

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

See also addAssetBundleFlash()View source

Arguments ​

  • $delete (boolean) – Whether to delete the stored flashes. Defaults to true.

Returns ​

array – The queued-up asset bundles.

getJsFlashes() ​

Returns the stored JS flashes.

See also addJsFlash()View source

Arguments ​

  • $delete (boolean) – Whether to delete the stored flashes. Defaults to true.

Returns ​

array – The stored JS flashes.

setError() ​

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.

View source

Arguments ​

  • $message (string) – The message.

setNotice() ​

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.

View source

Arguments ​

  • $message (string) – The message.