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()
.
Property Summary
-
$_autoLayout protected
bool
Whether or not autoLayout should be enabled.
-
$_className protected
string
The view class name to use. Can either use plugin notation, a short name or a fully namespaced classname.
-
$_helpers protected
array
The helpers to use
-
$_layout protected
string
The layout name to render.
-
$_layoutPath protected
string
The layout path to build the view with.
-
$_name protected
string
The view variables to use
-
$_options protected
array
Additional options used when constructing the view.
-
$_plugin protected
string
The plugin name to use.
-
$_template protected
string
The template file to render.
-
$_templatePath protected
string
The subdirectory to the template.
-
$_theme protected
string
The theme name to use.
Method Summary
-
autoLayout() public
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.
-
build() public
Using the data in the builder, create a view instance.
-
className() public
Get/set the view classname.
-
createFromArray() public
Configures a view builder instance from serialized config.
-
helpers() public
The helpers to use
-
jsonSerialize() public
Serializes the view builder object to a value that can be natively serialized and re-used to clone this builder instance.
-
layout() public
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.
-
layoutPath() public
Get/set path for layout files.
-
name() public
Get/set the view name
-
options() public
Set additional options for the view.
-
plugin() public
The plugin name to use
-
serialize() public
Serializes the view builder object.
-
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. -
templatePath() public
Get/set path for template files.
-
theme() public
The view theme to use.
-
unserialize() public
Unserializes the view builder object.
Method Detail
autoLayout() ¶ public
autoLayout(bool|null $autoLayout = null): bool|$this
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
$autoLayout optional Boolean to turn on/off. If null returns current value.
Returns
bool|$this
build() ¶ public
build(array $vars = [], Cake\Network\Request $request = null, Cake\Network\Response $response = null, Cake\Event\EventManager $events = null): Cake\View\View
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\Network\Request
$request optional The request to use.
-
Cake\Network\Response
$response optional The response to use.
-
Cake\Event\EventManager
$events optional The event manager to use.
Returns
Cake\View\View
Throws
Cake\View\Exception\MissingViewException
className() ¶ public
className(string|null $name = null): array|$this
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
array|$this
createFromArray() ¶ public
createFromArray(array $config): $this
Configures a view builder instance from serialized config.
Parameters
-
array
$config View builder configuration array.
Returns
$this
helpers() ¶ public
helpers(array|null $helpers = null, bool $merge = true): array|$this
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
jsonSerialize() ¶ public
jsonSerialize(): array
Serializes the view builder object to a value that can be natively serialized and re-used to clone this builder instance.
Returns
array
layout() ¶ public
layout(string|null $name = null): string|$this
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(string|null $path = null): string|$this
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(string|null $name = null): array|$this
Get/set the view name
Parameters
-
string|null
$name optional The name of the view
Returns
array|$this
options() ¶ public
options(array|null $options = null, bool $merge = true): array|$this
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(string|null|false $name = null): string|$this
The plugin name to use
Parameters
-
string|null|false
$name optional Plugin name. If null returns current plugin. Use false to remove the current plugin name.
Returns
string|$this
template() ¶ public
template(string|null $name = null): string|$this
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(string|null $path = null): string|$this
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(string|null|false $theme = null): string|$this
The view theme to use.
Parameters
-
string|null|false
$theme optional Theme name. If null returns current theme. Use false to remove the current theme.
Returns
string|$this
unserialize() ¶ public
unserialize(string $data): $this
Unserializes the view builder object.
Parameters
-
string
$data Serialized string.
Returns
$this
Property Detail
$_className ¶ protected
The view class name to use. Can either use plugin notation, a short name or a fully namespaced classname.
Type
string
$_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