\Cake\ViewViewVarsTrait

Provides the set() method for collecting template context.

Once collected context data can be passed to another object. This is done in Controller, TemplateTask and View for example.

Summary

Methods
Properties
Constants
viewBuilder()
createView()
set()
viewOptions()
$viewClass
$viewVars
$_validViewOptions
No constants found
No protected methods found
$_viewBuilder
N/A
No private methods found
No private properties found
N/A

Properties

$viewClass

$viewClass : string|null

The name of default View class.

Type

string|null

$viewVars

$viewVars : array

Variables for the view

Type

array

$_validViewOptions

$_validViewOptions : array

Type

array

$_viewBuilder

$_viewBuilder : \Cake\View\ViewBuilder

The view builder instance being used.

Type

\Cake\View\ViewBuilder

Methods

viewBuilder()

viewBuilder() : \Cake\View\ViewBuilder

Get the view builder being used.

Returns

\Cake\View\ViewBuilder

createView()

createView(string|null  $viewClass = null) : \Cake\View\View

Constructs the view class instance based on the current configuration.

Parameters

string|null $viewClass

Optional namespaced class name of the View class to instantiate.

Throws

\Cake\View\Exception\MissingViewException

If view class was not found.

Returns

\Cake\View\View

set()

set(string|array  $name, mixed  $value = null) : $this

Saves a variable or an associative array of variables for use inside a template.

Parameters

string|array $name

A string or an array of data.

mixed $value

Value in case $name is a string (which then works as the key). Unused if $name is an associative array, otherwise serves as the values to $name's keys.

Returns

$this

viewOptions()

viewOptions(string|array|null  $options = null, boolean  $merge = true) : array

Get/Set valid view options in the object's _validViewOptions property. The property is created as an empty array if it is not set. If called without any parameters it will return the current list of valid view options. See `createView()`.

Parameters

string|array|null $options

string or array of string to be appended to _validViewOptions.

boolean $merge

Whether to merge with or override existing valid View options. Defaults to true.

Returns

array —

The updated view options as an array.