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|nullWhether or not autoLayout should be enabled.
-
$_className protected
string|nullThe view class name to use. Can either use plugin notation, a short name or a fully namespaced classname.
-
$_helpers protected
arrayThe helpers to use
-
$_layout protected
string|false|nullThe layout name to render.
-
$_layoutPath protected
string|nullThe layout path to build the view with.
-
$_name protected
string|nullThe view variables to use
-
$_options protected
arrayAdditional options used when constructing the view.
-
$_plugin protected
string|false|nullThe plugin name to use.
-
$_template protected
string|nullThe template file to render.
-
$_templatePath protected
string|nullThe subdirectory to the template.
-
$_theme protected
string|false|nullThe theme name to use.
-
$_vars protected
arrayView vars
Method Summary
-
autoLayout() public deprecated
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 deprecated
Get/set the view classname.
-
createFromArray() public
Configures a view builder instance from serialized config.
-
disableAutoLayout() public
Turns off CakePHP's conventional mode of applying layout files.
-
enableAutoLayout() 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.
-
getClassName() public
Gets the view classname.
-
getHelpers() public
Gets the helpers to use.
-
getLayout() public
Gets the name of the layout file to render the view inside of.
-
getLayoutPath() public
Gets path for layout files.
-
getName() public
Gets the view name.
-
getOptions() public
Gets additional options for the view.
-
getPlugin() public
Gets the plugin name to use.
-
getTemplate() public
Gets the name of the view file to render. The name specified is the filename in /src/Template/
without the .ctp extension. -
getTemplatePath() public
Gets path for template files.
-
getTheme() public
Gets the view theme to use.
-
getVar() public
Get view var
-
getVars() public
Get all view vars.
-
hasVar() public
Check if view var is set.
-
helpers() public deprecated
The helpers to use
-
isAutoLayoutEnabled() public
Returns if CakePHP's conventional mode of applying layout files is enabled. Disabled means that layouts will not be automatically applied to rendered views.
-
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 deprecated
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 deprecated
Get/set path for layout files.
-
name() public deprecated
Get/set the view name
-
options() public deprecated
Set additional options for the view.
-
plugin() public deprecated
The plugin name to use
-
serialize() public
Serializes the view builder object.
-
setClassName() public
Sets the view classname.
-
setHelpers() public
Sets the helpers to use.
-
setLayout() public
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.
-
setLayoutPath() public
Sets path for layout files.
-
setName() public
Sets the view name.
-
setOptions() public
Sets additional options for the view.
-
setPlugin() public
Sets the plugin name to use.
-
setTemplate() public
Sets the name of the view file to render. The name specified is the filename in /src/Template/
without the .ctp extension. -
setTemplatePath() public
Sets path for template files.
-
setTheme() public
Sets the view theme to use.
-
setVar() public
Saves a variable for use inside a template.
-
setVars() public
Saves view vars for use inside templates.
-
template() public deprecated
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 deprecated
Get/set path for template files.
-
theme() public deprecated
The view theme to use.
-
unserialize() public
Unserializes the view builder object.
Method Detail
autoLayout() ¶ public
autoLayout(bool|null $enable = 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$enable optional Boolean to turn on/off. If null returns current value.
Returns
bool|$thisbuild() ¶ public
build(array $vars = [], Cake\Http\ServerRequest|null $request = null, Cake\Http\Response|null $response = null, Cake\Event\EventManager|null $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\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\ViewThrows
Cake\View\Exception\MissingViewExceptionclassName() ¶ public
className(string|null $name = null): string|$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
string|$thiscreateFromArray() ¶ public
createFromArray(array $config): $this
Configures a view builder instance from serialized config.
Parameters
-
array$config View builder configuration array.
Returns
$thisConfigured view builder instance.
disableAutoLayout() ¶ public
disableAutoLayout(): $this
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
$thisenableAutoLayout() ¶ public
enableAutoLayout(bool $enable = true): $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$enable optional Boolean to turn on/off.
Returns
$thisgetLayout() ¶ public
getLayout(): string|false|null
Gets the name of the layout file to render the view inside of.
Returns
string|false|nullgetLayoutPath() ¶ public
getLayoutPath(): string|null
Gets path for layout files.
Returns
string|nullgetPlugin() ¶ public
getPlugin(): string|false|null
Gets the plugin name to use.
Returns
string|false|nullgetTemplate() ¶ public
getTemplate(): string|null
Gets the name of the view file to render. The name specified is the
filename in /src/Template/
Returns
string|nullgetTemplatePath() ¶ public
getTemplatePath(): string|null
Gets path for template files.
Returns
string|nullgetTheme() ¶ public
getTheme(): string|false|null
Gets the view theme to use.
Returns
string|false|nullgetVar() ¶ public
getVar(string $name): mixed
Get view var
Parameters
-
string$name Var name
Returns
mixedThe var value or null if unset.
hasVar() ¶ public
hasVar(string $name): bool
Check if view var is set.
Parameters
-
string$name Var name
Returns
boolhelpers() ¶ 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|$thisisAutoLayoutEnabled() ¶ public
isAutoLayoutEnabled(): bool|null
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|nulljsonSerialize() ¶ 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
arraySerializable array of configuration properties.
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|$thislayoutPath() ¶ 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|$thisname() ¶ public
name(string|null $name = null): string|$this
Get/set the view name
Parameters
-
string|null$name optional The name of the view
Returns
string|$thisoptions() ¶ 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|$thisplugin() ¶ public
plugin(string|false|null $name = null): string|false|null|$this
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|$thissetClassName() ¶ public
setClassName(string|null $name): $this
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
$thissetHelpers() ¶ public
setHelpers(array $helpers, bool $merge = true): $this
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
$thissetLayout() ¶ public
setLayout(string|false|null $name): $this
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
$thissetLayoutPath() ¶ public
setLayoutPath(string|null $path): $this
Sets path for layout files.
Parameters
-
string|null$path Path for layout files.
Returns
$thissetName() ¶ public
setName(string|null $name): $this
Sets the view name.
Parameters
-
string|null$name The name of the view.
Returns
$thissetOptions() ¶ public
setOptions(array $options, bool $merge = true): $this
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
$thissetPlugin() ¶ public
setPlugin(string|false|null $name): $this
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
$thissetTemplate() ¶ public
setTemplate(string|null $name): $this
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
$thissetTemplatePath() ¶ public
setTemplatePath(string|null $path): $this
Sets path for template files.
Parameters
-
string|null$path Path for view files.
Returns
$thissetTheme() ¶ public
setTheme(string|false|null $theme): $this
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
$thissetVar() ¶ public
setVar(string $name, mixed $value = null): $this
Saves a variable for use inside a template.
Parameters
-
string$name A string or an array of data.
-
mixed$value optional Value.
Returns
$thissetVars() ¶ public
setVars(array $data, bool $merge = true): $this
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
$thistemplate() ¶ 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|$thistemplatePath() ¶ 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|$thistheme() ¶ public
theme(string|false|null $theme = null): string|false|null|$this
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|$thisunserialize() ¶ public
unserialize(string $data): $this
Unserializes the view builder object.
Parameters
-
string$data Serialized string.
Returns
$thisConfigured view builder instance.
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|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