Craft 3 Class Reference

Class craft\web\twig\variables\CraftVariable

Inheritance
craft\web\twig\variables\CraftVariable » yii\di\ServiceLocator » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/web/twig/variables/CraftVariable.php

Craft defines the craft global template variable.

Public Properties
Property Type Description Defined By
$app craft\web\Application, craft\console\Application, null The Craft application class craft\web\twig\variables\CraftVariable
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. craft\web\twig\variables\CraftVariable
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. craft\web\twig\variables\CraftVariable
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
assets() Returns a new AssetQuery instance. craft\web\twig\variables\CraftVariable
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
behaviors() Returns a list of behaviors that this component should behave as. craft\web\twig\variables\CraftVariable
canGetProperty() Returns a value indicating whether a property can be read. craft\web\twig\variables\CraftVariable
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
categories() Returns a new CategoryQuery instance. craft\web\twig\variables\CraftVariable
className() Returns the fully qualified name of this class. yii\base\BaseObject
clear() Removes the component from the locator. yii\di\ServiceLocator
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
entries() Returns a new EntryQuery instance. craft\web\twig\variables\CraftVariable
get() Returns the component instance with the specified ID. yii\di\ServiceLocator
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getComponents() Returns the list of the component definitions or the loaded component instances. yii\di\ServiceLocator
has() Returns a value indicating whether the locator has the specified component definition or has instantiated the component. yii\di\ServiceLocator
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. craft\web\twig\variables\CraftVariable
isLocalized() Returns whether this site has multiple locales. craft\web\twig\variables\CraftVariable
locale() Gets the current language in use. craft\web\twig\variables\CraftVariable
matrixBlocks() Returns a new MatrixBlockQuery instance. craft\web\twig\variables\CraftVariable
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
set() Registers a component definition with this locator. yii\di\ServiceLocator
setComponents() Registers a set of component definitions in this locator. yii\di\ServiceLocator
tags() Returns a new TagQuery instance. craft\web\twig\variables\CraftVariable
trigger() Triggers an event. yii\base\Component
users() Returns a new UserQuery instance craft\web\twig\variables\CraftVariable
Events
Event Type Description Defined By
EVENT_DEFINE_BEHAVIORS craft\events\DefineBehaviorsEvent The event that is triggered when defining the class behaviors craft\web\twig\variables\CraftVariable
EVENT_DEFINE_COMPONENTS craft\events\DefineComponentsEvent The event that is triggered when defining the Service Locator components. craft\web\twig\variables\CraftVariable
EVENT_INIT yii\base\Event The event that is triggered after the component's init cycle craft\web\twig\variables\CraftVariable

Property Details

$app public property #

The Craft application class

public craft\web\Application, craft\console\Application, null $app null

Method Details

__call() public method #

Calls the named method which is not a class method.

This method will check if any attached behavior has the named method and will execute it if available.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

public mixed __call ( $name, $params )
$name string The method name
$params array Method parameters
return mixed The method return value
throws yii\base\UnknownMethodException when calling unknown method

__construct() public method #

Constructor.

The default implementation does two things:

If this method is overridden in a child class, it is recommended that

public void __construct ( $config = [] )
$config array Name-value pairs that will be used to initialize the object properties

assets() public method #

Returns a new AssetQuery instance.

public craft\elements\db\AssetQuery assets ( $criteria null )
$criteria mixed

behaviors() public method #

Returns a list of behaviors that this component should behave as.

Child classes may override this method to specify the behaviors they want to behave as.

The return value of this method should be an array of behavior objects or configurations indexed by behavior names. A behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName' => [
    'class' => 'BehaviorClass',
    'property1' => 'value1',
    'property2' => 'value2',
]

Note that a behavior class must extend from \craft\web\twig\variables\Behavior. Behaviors can be attached using a name or anonymously. When a name is used as the array key, using this name, the behavior can later be retrieved using getBehavior() or be detached using detachBehavior(). Anonymous behaviors can not be retrieved or detached.

Behaviors declared in this method will be attached to the component automatically (on demand).

public array behaviors ( )
return array The behavior configurations.

canGetProperty() public method #

Returns a value indicating whether a property can be read.

A property can be read if:

public boolean canGetProperty ( $name, $checkVars true, $checkBehaviors true )
$name string The property name
$checkVars boolean Whether to treat member variables as properties
$checkBehaviors boolean Whether to treat behaviors' properties as properties of this component
return boolean Whether the property can be read

categories() public method #

Returns a new CategoryQuery instance.

public craft\elements\db\CategoryQuery categories ( $criteria null )
$criteria mixed

entries() public method #

Returns a new EntryQuery instance.

public craft\elements\db\EntryQuery entries ( $criteria null )
$criteria mixed

init() public method #

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )

isLocalized() public method #

Deprecated in 3.0. Use craft.app.isMultiSite instead

Returns whether this site has multiple locales.

public boolean isLocalized ( )

locale() public method #

Deprecated in 3.0

Gets the current language in use.

public string locale ( )

matrixBlocks() public method #

Returns a new MatrixBlockQuery instance.

public craft\elements\db\MatrixBlockQuery matrixBlocks ( $criteria null )
$criteria mixed

tags() public method #

Returns a new TagQuery instance.

public craft\elements\db\TagQuery tags ( $criteria null )
$criteria mixed

users() public method #

Returns a new UserQuery instance

public craft\elements\db\UserQuery users ( $criteria null )
$criteria mixed

Event Details

EVENT_DEFINE_BEHAVIORS event of type craft\events\DefineBehaviorsEvent #

The event that is triggered when defining the class behaviors

See also behaviors().

EVENT_DEFINE_COMPONENTS event of type craft\events\DefineComponentsEvent #

Deprecated since 3.0.0-beta.23

The event that is triggered when defining the Service Locator components.

See also __construct().

EVENT_INIT event of type yii\base\Event #

The event that is triggered after the component's init cycle

See also init().