CraftVariable ​
- Type
- Class
- Namespace
- craft\web\twig\variables
- Inherits
- craft\web\twig\variables\CraftVariable » yii\di\ServiceLocator » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.0.0
Craft defines the craft
global template variable.
Public Properties ​
Property | Description |
---|---|
app | craft\web\Application, craft\console\Application, null – The Craft application class |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
components | array – The list of the component definitions or the loaded component instances (ID => definition or instance). |
cp | craft\web\twig\variables\Cp |
io | craft\web\twig\variables\Io |
rebrand | craft\web\twig\variables\Rebrand |
routes | craft\web\twig\variables\Routes |
app
​
- Type
- craft\web\Application, craft\console\Application, null
- Default value
null
The Craft application class
cp
​
- Type
- craft\web\twig\variables\Cp
- Default value
null
io
​
- Type
- craft\web\twig\variables\Io
- Default value
null
rebrand
​
- Type
- craft\web\twig\variables\Rebrand
- Default value
null
routes
​
- Type
- craft\web\twig\variables\Routes
- Default value
null
Public Methods ​
Method | Description |
---|---|
__call() | Calls the named method which is not a class method. |
__clone() | This method is called after the object is created by cloning an existing one. |
__construct() | Constructor. |
__get() | Getter magic method. |
__isset() | Checks if a property value is null. |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be null. |
addresses() | Returns a new address query. |
assets() | Returns a new asset query. |
attachBehavior() | Attaches a behavior to this component. |
attachBehaviors() | Attaches a list of behaviors to the component. |
behaviors() | Returns a list of behaviors that this component should behave as. |
canGetProperty() | Returns a value indicating whether a property can be read. |
canSetProperty() | Returns a value indicating whether a property can be set. |
categories() | Returns a new category query. |
className() | Returns the fully qualified name of this class. |
clear() | Removes the component from the locator. |
detachBehavior() | Detaches a behavior from the component. |
detachBehaviors() | Detaches all behaviors from the component. |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
entries() | Returns a new entry query. |
get() | Returns the component instance with the specified ID. |
getBehavior() | Returns the named behavior object. |
getBehaviors() | Returns all behaviors attached to this component. |
getComponents() | Returns the list of the component definitions or the loaded component instances. |
globalSets() | Returns a new global set query. |
has() | Returns a value indicating whether the locator has the specified component definition or has instantiated the component. |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() | Returns a value indicating whether a method is defined. |
hasProperty() | Returns a value indicating whether a property is defined for this component. |
init() | Initializes the object. |
matrixBlocks() | Returns a new Matrix block query. |
off() | Detaches an existing event handler from this component. |
on() | Attaches an event handler to an event. |
query() | Returns a new generic query. |
set() | Registers a component definition with this locator. |
setComponents() | Registers a set of component definitions in this locator. |
tags() | Returns a new tag query. |
trigger() | Triggers an event. |
users() | Returns a new user query. |
__call()
​
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.
Arguments ​
Returns ​
mixed
– The method return value
Throws ​
- yii\base\UnknownMethodException
when calling unknown method
__construct()
​
Constructor.
The default implementation does two things:
- Initializes the object with the given configuration
$config
. - Call init().
If this method is overridden in a child class, it is recommended that
- the last parameter of the constructor is a configuration array, like
$config
here. - call the parent implementation at the end of the constructor.
Arguments ​
$config
(array) – Name-value pairs that will be used to initialize the object properties
addresses()
​
Returns a new address query.
Arguments ​
$criteria
(array)
Returns ​
craft\elements\db\AddressQuery
assets()
​
Returns a new asset query.
Arguments ​
$criteria
(array)
Returns ​
behaviors()
​
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).
Returns ​
array – The behavior configurations.
canGetProperty()
​
Returns a value indicating whether a property can be read.
A property can be read if:
- the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when
$checkVars
is true); - an attached behavior has a readable property of the given name (when
$checkBehaviors
is true).
Arguments ​
$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
Returns ​
boolean – Whether the property can be read
categories()
​
Returns a new category query.
Arguments ​
$criteria
(array)
Returns ​
craft\elements\db\CategoryQuery
entries()
​
Returns a new entry query.
Arguments ​
$criteria
(array)
Returns ​
globalSets()
​
- Since
- 3.0.4
Returns a new global set query.
Arguments ​
$criteria
(array)
Returns ​
craft\elements\db\GlobalSetQuery
init()
​
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
matrixBlocks()
​
Returns a new Matrix block query.
Arguments ​
$criteria
(array)
Returns ​
craft\elements\db\MatrixBlockQuery
query()
​
- Since
- 3.0.19
Returns a new generic query.
Returns ​
tags()
​
Returns a new tag query.
Arguments ​
$criteria
(array)
Returns ​
users()
​
Returns a new user query.
Arguments ​
$criteria
(array)
Returns ​
Events ​
EVENT_DEFINE_BEHAVIORS ​
The event that is triggered when defining the class behaviors
See also behaviors()
EVENT_INIT ​
- Type
- yii\base\Event
The event that is triggered after the component's init cycle
See also init()