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, null
jsFlashKeystring – The name of the flash key that stores JS data
jsFlashesarray – The stored JS flashes.
noticestring, null
ownercraft\web\Session
successstring, null

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, null
Default value
null

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, null
Default value
null

View source

owner ​

Type
craft\web\Session
Default value
null

View source

success ​

Type
string, null
Default value
null
Since
4.2.0

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.
broadcastToJs()Broadcasts a message to all tabs opened to the control panel.
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.
getError()Retrieves an error message from the user’s flash data.
getJsFlashes()Returns the stored JS flashes.
getNotice()Retrieves a notice from the user’s flash data.
getSuccess()Retrieves a success message from the user’s flash data.
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.
setSuccess()Stores a success message 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 (class-string<\yii\web\AssetBundle>) – The class name of the asset bundle
  • $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 ​

broadcastToJs() ​

Since
4.0.0

Broadcasts a message to all tabs opened to the control panel.

View source

Arguments ​

  • $message (string, array) – The message to broadcast.

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.

getError() ​

Retrieves an error message from the user’s flash data.

View source

Returns ​

string, null

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.

getNotice() ​

Retrieves a notice from the user’s flash data.

View source

Returns ​

string, null

getSuccess() ​

Since
4.2.0

Retrieves a success message from the user’s flash data.

View source

Returns ​

string, null

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
  • $settings (array) – The control panel notification settings

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
  • $settings (array) – The control panel notification settings

setSuccess() ​

Since
4.2.0

Stores a success 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 success message can be stored at a time.

View source

Arguments ​

  • $message (string) – The message
  • $settings (array) – The control panel notification settings