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.
Public Properties ​
Property | Description |
---|---|
assetBundleFlashKey | string – The name of the flash key that stores asset bundle data |
assetBundleFlashes | array – The queued-up asset bundles. |
authAccessParam | string, null – The session variable name used to store the authorization keys for the current session. |
error | string, null |
jsFlashKey | string – The name of the flash key that stores JS data |
jsFlashes | array – The stored JS flashes. |
notice | string, null |
owner | craft\web\Session |
success | string, null |
assetBundleFlashKey
​
- Type
- string
- Default value
'__ab'
The name of the flash key that stores asset bundle data
assetBundleFlashes
​
- Type
- array
- Default value
null
- Access
- Read-only
The queued-up asset bundles.
authAccessParam
​
The session variable name used to store the authorization keys for the current session.
See also:
error
​
jsFlashKey
​
- Type
- string
- Default value
'__js'
The name of the flash key that stores JS data
jsFlashes
​
- Type
- array
- Default value
null
- Access
- Read-only
The stored JS flashes.
notice
​
owner
​
- Type
- craft\web\Session
- Default value
null
success
​
Public Methods ​
Method | Description |
---|---|
__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 ​
- yii\base\Exception
if $name isn't an asset bundle class name
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:
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.
Arguments ​
$action
(string)
broadcastToJs()
​
- Since
- 4.0.0
Broadcasts a message to all tabs opened to the control panel.
Arguments ​
checkAuthorization()
​
Returns whether the user is authorized to perform an action.
Arguments ​
$action
(string)
Returns ​
deauthorize()
​
Deauthorizes the user from performing an action.
Arguments ​
$action
(string)
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 totrue
.
Returns ​
array – The queued-up asset bundles.
getError()
​
Retrieves an error message from the user’s flash data.
Returns ​
getJsFlashes()
​
Returns the stored JS flashes.
See also addJsFlash()View source
Arguments ​
$delete
(boolean) – Whether to delete the stored flashes. Defaults totrue
.
Returns ​
array – The stored JS flashes.
getNotice()
​
Retrieves a notice from the user’s flash data.
Returns ​
getSuccess()
​
- Since
- 4.2.0
Retrieves a success message from the user’s flash data.
Returns ​
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.
Arguments ​
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.
Arguments ​
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 notice can be stored at a time.