Class ViewBuilder
Provides an API for iteratively building a view up.
Once you have configured the view and established all the context you can create a view instance with build()
.
Properties summary
- $_autoLayout protected
bool|null
Whether or not autoLayout should be enabled.
- $_className protected
string|null
The view class name to use.
- $_helpers protected
array
The helpers to use
- $_layout protected
string|false|null
The layout name to render.
- $_layoutPath protected
string|null
The layout path to build the view with.
- $_name protected
string|null
The view variables to use
- $_options protected
array
Additional options used when constructing the view.
- $_plugin protected
string|false|null
The plugin name to use.
- $_template protected
string|null
The template file to render.
- $_templatePath protected
string|null
The subdirectory to the template.
- $_theme protected
string|false|null
The theme name to use.
- $_vars protected
array
View vars
Method Summary
- getTemplate() public
Gets the name of the view file to render. The name specified is the filename in /src/Template/
without the .ctp extension. - isAutoLayoutEnabled() public
Returns if CakePHP's conventional mode of applying layout files is enabled.
- jsonSerialize() public
Serializes the view builder object to a value that can be natively serialized and re-used to clone this builder instance.
- setTemplate() public
Sets the name of the view file to render. The name specified is the filename in /src/Template/
without the .ctp extension. - template() public
Get/set the name of the view file to render. The name specified is the filename in /src/Template/
without the .ctp extension.
Method Detail
autoLayout() public
autoLayout(mixed $enable)
Turns on or off CakePHP's conventional mode of applying layout files.
On by default. Setting to off means that layouts will not be automatically applied to rendered views.
Parameters
-
bool|null
$enable optional Boolean to turn on/off. If null returns current value.
Returns
bool|$this
build() public
build(mixed $vars, \Cake\Http\ServerRequest $request, \Cake\Http\Response $response, \Cake\Event\EventManager $events)
Using the data in the builder, create a view instance.
If className() is null, App\View\AppView will be used. If that class does not exist, then Cake\View\View will be used.
Parameters
-
array
$vars optional The view variables/context to use.
-
\Cake\Http\ServerRequest|null
$request optional The request to use.
-
\Cake\Http\Response|null
$response optional The response to use.
-
\Cake\Event\EventManager|null
$events optional The event manager to use.
Returns
\Cake\View\View
Throws
Cake\View\Exception\MissingViewException
className() public
className(mixed $name)
Get/set the view classname.
Accepts either a short name (Ajax) a plugin name (MyPlugin.Ajax) or a fully namespaced name (App\View\AppView).
Parameters
-
string|null
$name optional The class name for the view. Can be a plugin.class name reference, a short alias, or a fully namespaced name.
Returns
string|$this
createFromArray() public
createFromArray(mixed $config)
Configures a view builder instance from serialized config.
Parameters
-
array
$config View builder configuration array.
Returns
$this
Configured view builder instance.
disableAutoLayout() public
disableAutoLayout()
Turns off CakePHP's conventional mode of applying layout files.
Setting to off means that layouts will not be automatically applied to rendered views.
Returns
$this
enableAutoLayout() public
enableAutoLayout(mixed $enable)
Turns on or off CakePHP's conventional mode of applying layout files.
On by default. Setting to off means that layouts will not be automatically applied to rendered views.
Parameters
-
bool
$enable optional Boolean to turn on/off.
Returns
$this
getClassName() public
getClassName()
Gets the view classname.
Returns
string|null
getHelpers() public
getHelpers()
Gets the helpers to use.
Returns
array
getLayout() public
getLayout()
Gets the name of the layout file to render the view inside of.
Returns
string|false|null
getLayoutPath() public
getLayoutPath()
Gets path for layout files.
Returns
string|null
getName() public
getName()
Gets the view name.
Returns
string|null
getOptions() public
getOptions()
Gets additional options for the view.
Returns
array
getPlugin() public
getPlugin()
Gets the plugin name to use.
Returns
string|false|null
getTemplate() public
getTemplate()
Gets the name of the view file to render. The name specified is the filename in /src/Template/
Returns
string|null
getTemplatePath() public
getTemplatePath()
Gets path for template files.
Returns
string|null
getTheme() public
getTheme()
Gets the view theme to use.
Returns
string|false|null
getVar() public
getVar(mixed $name)
Get view var
Parameters
-
string
$name Var name
Returns
mixed
The var value or null if unset.
getVars() public
getVars()
Get all view vars.
Returns
array
hasVar() public
hasVar(mixed $name)
Check if view var is set.
Parameters
-
string
$name Var name
Returns
bool
helpers() public
helpers(array $helpers, mixed $merge)
The helpers to use
Parameters
-
array|null
$helpers optional Helpers to use.
-
bool
$merge optional Whether or not to merge existing data with the new data.
Returns
array|$this
isAutoLayoutEnabled() public
isAutoLayoutEnabled()
Returns if CakePHP's conventional mode of applying layout files is enabled.
Disabled means that layouts will not be automatically applied to rendered views.
Returns
bool|null
jsonSerialize() public
jsonSerialize()
Serializes the view builder object to a value that can be natively serialized and re-used to clone this builder instance.
Returns
array
Serializable array of configuration properties.
layout() public
layout(mixed $name)
Get/set the name of the layout file to render the view inside of.
The name specified is the filename of the layout in /src/Template/Layout without the .ctp extension.
Parameters
-
string|null
$name optional Layout file name to set. If null returns current name.
Returns
string|$this
layoutPath() public
layoutPath(mixed $path)
Get/set path for layout files.
Parameters
-
string|null
$path optional Path for layout files. If null returns current path.
Returns
string|$this
name() public
name(mixed $name)
Get/set the view name
Parameters
-
string|null
$name optional The name of the view
Returns
string|$this
options() public
options(array $options, mixed $merge)
Set additional options for the view.
This lets you provide custom constructor arguments to application/plugin view classes.
Parameters
-
array|null
$options optional Either an array of options or null to get current options.
-
bool
$merge optional Whether or not to merge existing data with the new data.
Returns
array|$this
plugin() public
plugin(mixed $name)
The plugin name to use
Parameters
-
string|false|null
$name optional Plugin name. If null returns current plugin. Use false to remove the current plugin name.
Returns
string|false|null|$this
serialize() public
serialize()
Serializes the view builder object.
Returns
string
setClassName() public
setClassName(mixed $name)
Sets the view classname.
Accepts either a short name (Ajax) a plugin name (MyPlugin.Ajax) or a fully namespaced name (App\View\AppView) or null to use the View class provided by CakePHP.
Parameters
-
string|null
$name The class name for the view.
Returns
$this
setHelpers() public
setHelpers(array $helpers, mixed $merge)
Sets the helpers to use.
Parameters
-
array
$helpers Helpers to use.
-
bool
$merge optional Whether or not to merge existing data with the new data.
Returns
$this
setLayout() public
setLayout(mixed $name)
Sets the name of the layout file to render the view inside of.
The name specified is the filename of the layout in /src/Template/Layout without the .ctp extension.
Parameters
-
string|false|null
$name Layout file name to set.
Returns
$this
setLayoutPath() public
setLayoutPath(mixed $path)
Sets path for layout files.
Parameters
-
string|null
$path Path for layout files.
Returns
$this
setName() public
setName(mixed $name)
Sets the view name.
Parameters
-
string|null
$name The name of the view.
Returns
$this
setOptions() public
setOptions(array $options, mixed $merge)
Sets additional options for the view.
This lets you provide custom constructor arguments to application/plugin view classes.
Parameters
-
array
$options An array of options.
-
bool
$merge optional Whether or not to merge existing data with the new data.
Returns
$this
setPlugin() public
setPlugin(mixed $name)
Sets the plugin name to use.
False
to remove current plugin name is deprecated as of 3.4.0. Use directly null
instead.
Parameters
-
string|false|null
$name Plugin name. Use null or false to remove the current plugin name.
Returns
$this
setTemplate() public
setTemplate(mixed $name)
Sets the name of the view file to render. The name specified is the filename in /src/Template/
Parameters
-
string|null
$name View file name to set.
Returns
$this
setTemplatePath() public
setTemplatePath(mixed $path)
Sets path for template files.
Parameters
-
string|null
$path Path for view files.
Returns
$this
setTheme() public
setTheme(mixed $theme)
Sets the view theme to use.
False
to remove current theme is deprecated as of 3.4.0. Use directly null
instead.
Parameters
-
string|false|null
$theme Theme name. Use null or false to remove the current theme.
Returns
$this
setVar() public
setVar(mixed $name, mixed $value)
Saves a variable for use inside a template.
Parameters
-
string
$name A string or an array of data.
-
mixed
$value optional Value.
Returns
$this
setVars() public
setVars(mixed $data, mixed $merge)
Saves view vars for use inside templates.
Parameters
-
array
$data Array of data.
-
bool
$merge optional Whether to merge with existing vars, default true.
Returns
$this
template() public
template(mixed $name)
Get/set the name of the view file to render. The name specified is the filename in /src/Template/
Parameters
-
string|null
$name optional View file name to set. If null returns current name.
Returns
string|$this
templatePath() public
templatePath(mixed $path)
Get/set path for template files.
Parameters
-
string|null
$path optional Path for view files. If null returns current path.
Returns
string|$this
theme() public
theme(mixed $theme)
The view theme to use.
Parameters
-
string|false|null
$theme optional Theme name. If null returns current theme. Use false to remove the current theme.
Returns
string|false|null|$this
unserialize() public
unserialize(mixed $data)
Unserializes the view builder object.
Parameters
-
string
$data Serialized string.
Returns
$this
Configured view builder instance.
Property Detail
$_autoLayout protected
Whether or not autoLayout should be enabled.
Type
bool|null
$_className protected
The view class name to use.
Can either use plugin notation, a short name or a fully namespaced classname.
Type
string|null
$_helpers protected
The helpers to use
Type
array
$_layout protected
The layout name to render.
Type
string|false|null
$_layoutPath protected
The layout path to build the view with.
Type
string|null
$_name protected
The view variables to use
Type
string|null
$_options protected
Additional options used when constructing the view.
This options array lets you provide custom constructor arguments to application/plugin view classes.
Type
array
$_plugin protected
The plugin name to use.
Type
string|false|null
$_template protected
The template file to render.
Type
string|null
$_templatePath protected
The subdirectory to the template.
Type
string|null
$_theme protected
The theme name to use.
Type
string|false|null
$_vars protected
View vars
Type
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.9/class-Cake.View.ViewBuilder.html