Trait ViewVarsTrait
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.
Direct Users
Indirect Users
- Cake\Controller\ErrorController
- Cake\View\AjaxView
- Cake\View\JsonView
- Cake\View\SerializedView
- Cake\View\XmlView
Properties summary
- The view builder instance being used.
$_viewBuilderprotected -
$viewClasspublicThe name of default View class.string|null -
$viewVarspublicVariables for the viewarray
Magic properties summary
-
$_validViewOptionspublicarray
Method Summary
- createView() publicConstructs the view class instance based on the current configuration.
- set() publicSaves a variable or an associative array of variables for use inside a template.
- viewBuilder() publicGet the view builder being used.
-
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().
Method Detail
createView()source public
createView( string|null $viewClass = null )
Constructs the view class instance based on the current configuration.
Parameters
- string|null
$viewClassoptional null - Optional namespaced class name of the View class to instantiate.
Returns
Cake\View\ViewThrows
Cake\View\Exception\MissingViewExceptionIf view class was not found.
set()source public
set( string|array $name , mixed $value = null )
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
$valueoptional null 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
viewBuilder()source public
viewBuilder( )
Get the view builder being used.
Returns
Cake\View\ViewBuilderviewOptions()source public deprecated
viewOptions( string|array|null $options = null , boolean $merge = true )
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().
Deprecated
3.7.0 Use ViewBuilder::setOptions() or any one of it's setter methods instead.Parameters
- string|array|null
$optionsoptional null - string or array of string to be appended to _validViewOptions.
- boolean
$mergeoptional true Whether to merge with or override existing valid View options. Defaults to
true.
Returns
arrayThe updated view options as an array.
Properties detail
$viewClasssource
public string|null
The name of default View class.
Deprecated
3.1.0 Use$this->viewBuilder()->getClassName()/$this->viewBuilder()->setClassName() instead.$viewVarssource
public array
Variables for the view
Deprecated
3.7.0 Use$this->set() instead, also see $this->viewBuilder()->getVar().[]
Magic properties detail
$_validViewOptionssource
public array
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.7/class-Cake.View.ViewVarsTrait.html