UserSession

Type
Class
Namespace
craft\web\twig\variables
Inherits
craft\web\twig\variables\UserSession
Since
3.0
Deprecated in
in 3.0

User session functions.

View source

Public Methods

MethodDescription
getFlash()Returns a flash message by a given key.
getFlashes()Returns all flash data for the user.
getRemainingSessionTime()Returns the number of seconds the user will be logged in for.
getRememberedUsername()Returns the remembered username from cookie.
getReturnUrl()Returns the URL the user was trying to access before getting sent to the login page.
getUser()Returns the currently logged in user.
hasFlash()Returns whether a flash message exists by a given key.
isLoggedIn()Returns whether the user is logged in.

getFlash()

Returns a flash message by a given key.

View source

Arguments

Returns

mixed

Signature

public mixed getFlash ( \craft\web\twig\variables\string $key, $defaultValue = null, \craft\web\twig\variables\bool $delete = true )

getFlashes()

Returns all flash data for the user.

View source

Arguments

Returns

array

Signature

public array getFlashes ( \craft\web\twig\variables\bool $delete = true )

getRemainingSessionTime()

Returns the number of seconds the user will be logged in for.

View source

Returns

integer

Signature

public integer getRemainingSessionTime ( )

getRememberedUsername()

Returns the remembered username from cookie.

View source

Returns

string

Signature

public string getRememberedUsername ( )

getReturnUrl()

Returns the URL the user was trying to access before getting sent to the login page.

View source

Arguments

  • $defaultUrl (string, null) – The default URL that should be returned if no return URL was stored.

Returns

string – The return URL, or|null $defaultUrl.

Signature

public string getReturnUrl ( \craft\web\twig\variables\string $defaultUrl = null )

getUser()

Returns the currently logged in user.

View source

Returns

craft\elements\User, null

Signature

public craft\elements\User, null getUser ( )

hasFlash()

Returns whether a flash message exists by a given key.

View source

Arguments

Returns

mixed

Signature

public mixed hasFlash ( \craft\web\twig\variables\string $key )

isLoggedIn()

Returns whether the user is logged in.

View source

Returns

boolean

Signature

public boolean isLoggedIn ( )