SessionBehavior

Type
Class
Namespace
craft\behaviors
Inherits
craft\behaviors\SessionBehavior » yii\base\Behavior » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.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.
$owneryii\base\Component, null – The owner of this behavior

$assetBundleFlashKey

Type
string

The name of the flash key that stores asset bundle data

View source

Signature

public string $assetBundleFlashKey = '__ab'

$assetBundleFlashes

Type
array
Access
Read-only

The queued-up asset bundles.

View source

Signature

public array getAssetBundleFlashes ( \craft\behaviors\bool $delete = false )

$authAccessParam

Type
string, null

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

See also:

View source

Signature

public string, null $authAccessParam = null

$error

Type
string
Access
Write-only

The message.

View source

Signature

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

$jsFlashKey

Type
string

The name of the flash key that stores JS data

View source

Signature

public string $jsFlashKey = '__js'

$jsFlashes

Type
array
Access
Read-only

The stored JS flashes.

View source

Signature

public array getJsFlashes ( \craft\behaviors\bool $delete = true )

$notice

Type
string
Access
Write-only

The message.

View source

Signature

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

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

Signature

public void addAssetBundleFlash ( \craft\behaviors\string $name, \craft\behaviors\int $position = null )

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.

Signature

public void addJsFlash ( \craft\behaviors\string $js, \craft\behaviors\int $position = \craft\web\View::POS_READY, \craft\behaviors\string $key = null )

authorize()

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

View source

Arguments

Signature

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

checkAuthorization()

Returns whether the user is authorized to perform an action.

View source

Arguments

Returns

boolean

Signature

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

deauthorize()

Deauthorizes the user from performing an action.

View source

Arguments

Signature

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

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.

Signature

public array getAssetBundleFlashes ( \craft\behaviors\bool $delete = false )

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.

Signature

public array getJsFlashes ( \craft\behaviors\bool $delete = true )

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.

Signature

public void setError ( \craft\behaviors\string $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.

Signature

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