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 – The message. |
jsFlashKey | string – The name of the flash key that stores JS data |
jsFlashes | array – The stored JS flashes. |
notice | string – The message. |
owner | craft\web\Session |
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
​
- Type
- string
- Default value
null
- Access
- Write-only
The message.
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
​
- Type
- string
- Default value
null
- Access
- Write-only
The message.
owner
​
- Type
- craft\web\Session
- Default value
null
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. |
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 ​
- 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)
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.
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.
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 ​
$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.
Arguments ​
$message
(string) – The message.