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().
boolWhether autoLayout should be enabled.
string|nullThe view class name to use. Can either use plugin notation, a short name or a fully namespaced classname.
arrayThe helpers to use
string|nullThe layout name to render.
string|nullThe layout path to build the view with.
string|nullThe view variables to use
array<string, mixed>Additional options used when constructing the view.
string|nullThe plugin name to use.
string|nullThe template file to render.
string|nullThe subdirectory to the template.
string|nullThe theme name to use.
array<string, mixed>View vars
Magic method used for serializing the view builder object.
Magic method used to rebuild the view builder object.
Iterates through hash to clean up and normalize.
Adds a helper to use.
Adds helpers to use by merging with existing ones.
Using the data in the builder, create a view instance.
Configures a view builder instance from serialized config.
Turns off CakePHP's conventional mode of applying layout files.
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.
Gets the view classname.
Gets the helpers to use.
Gets the name of the layout file to render the view inside of.
Gets path for layout files.
Gets the view name.
Get view option.
Gets additional options for the view.
Gets the plugin name to use.
Gets the name of the view file to render. The name specified is the filename in templates/<SubFolder>/ without the .php extension.
Gets path for template files.
Gets the view theme to use.
Get view var
Get all view vars.
Check if view var is set.
Returns if CakePHP's conventional mode of applying layout files is enabled. Disabled means that layouts will not be automatically applied to rendered views.
Serializes the view builder object to a value that can be natively serialized and re-used to clone this builder instance.
Serializes the view builder object.
Sets the view classname.
Sets the helpers to use.
Sets the name of the layout file to render the view inside of. The name specified is the filename of the layout in templates/layout/ without the .php extension.
Sets path for layout files.
Sets the view name.
Set view option.
Sets additional options for the view.
Sets the plugin name to use.
Sets the name of the view file to render. The name specified is the filename in templates/<SubFolder>/ without the .php extension.
Sets path for template files.
Sets the view theme to use.
Saves a variable for use inside a template.
Saves view vars for use inside templates.
Unserializes the view builder object.
__serialize(): array
Magic method used for serializing the view builder object.
array__unserialize(array<string, mixed> $data): void
Magic method used to rebuild the view builder object.
array<string, mixed> $data Data array.
void_checkViewVars(mixed $item, string $key): void
Iterates through hash to clean up and normalize.
mixed $item Reference to the view var value.
string $key View var key.
voidRuntimeExceptionaddHelper(string $helper, array<string, mixed> $options = []): $this
Adds a helper to use.
string $helper Helper to use.
array<string, mixed> $options optional Options.
$thisaddHelpers(array $helpers): $this
Adds helpers to use by merging with existing ones.
array $helpers Helpers to use.
$thisbuild(array<string, mixed> $vars = [], Cake\Http\ServerRequest|null $request = null, Cake\Http\Response|null $response = null, Cake\Event\EventManagerInterface|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 {@link \Cake\View\View} will be used.
array<string, mixed> $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\EventManagerInterface|null $events optional The event manager to use.
Cake\View\ViewCake\View\Exception\MissingViewExceptioncreateFromArray(array<string, mixed> $config): $this
Configures a view builder instance from serialized config.
array<string, mixed> $config View builder configuration array.
$thisdisableAutoLayout(): $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.
$thisenableAutoLayout(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.
bool $enable optional Boolean to turn on/off.
$thisgetClassName(): string|null
Gets the view classname.
string|nullgetHelpers(): array
Gets the helpers to use.
arraygetLayout(): string|null
Gets the name of the layout file to render the view inside of.
string|nullgetLayoutPath(): string|null
Gets path for layout files.
string|nullgetName(): string|null
Gets the view name.
string|nullgetOption(string $name): mixed
Get view option.
string $name The name of the option.
mixedgetOptions(): array<string, mixed>
Gets additional options for the view.
array<string, mixed>getPlugin(): string|null
Gets the plugin name to use.
string|nullgetTemplate(): string|null
Gets the name of the view file to render. The name specified is the filename in templates/<SubFolder>/ without the .php extension.
string|nullgetTemplatePath(): string|null
Gets path for template files.
string|nullgetTheme(): string|null
Gets the view theme to use.
string|nullgetVar(string $name): mixed
Get view var
string $name Var name
mixedgetVars(): array<string, mixed>
Get all view vars.
array<string, mixed>hasVar(string $name): bool
Check if view var is set.
string $name Var name
boolisAutoLayoutEnabled(): bool
Returns if CakePHP's conventional mode of applying layout files is enabled. Disabled means that layouts will not be automatically applied to rendered views.
booljsonSerialize(): array
Serializes the view builder object to a value that can be natively serialized and re-used to clone this builder instance.
There are limitations for viewVars that are good to know:
arrayserialize(): string
Serializes the view builder object.
stringsetClassName(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.
string|null $name The class name for the view.
$thissetHelpers(array $helpers, bool $merge = true): $this
Sets the helpers to use.
array $helpers Helpers to use.
bool $merge optional Whether to merge existing data with the new data.
$thissetLayout(string|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 templates/layout/ without the .php extension.
string|null $name Layout file name to set.
$thissetLayoutPath(string|null $path): $this
Sets path for layout files.
string|null $path Path for layout files.
$thissetName(string|null $name): $this
Sets the view name.
string|null $name The name of the view, or null to remove the current name.
$thissetOption(string $name, mixed $value): $this
Set view option.
string $name The name of the option.
mixed $value Value to set.
$thissetOptions(array<string, mixed> $options, bool $merge = true): $this
Sets additional options for the view.
This lets you provide custom constructor arguments to application/plugin view classes.
array<string, mixed> $options An array of options.
bool $merge optional Whether to merge existing data with the new data.
$thissetPlugin(string|null $name): $this
Sets the plugin name to use.
string|null $name Plugin name. Use null to remove the current plugin name.
$thissetTemplate(string|null $name): $this
Sets the name of the view file to render. The name specified is the filename in templates/<SubFolder>/ without the .php extension.
string|null $name View file name to set, or null to remove the template name.
$thissetTemplatePath(string|null $path): $this
Sets path for template files.
string|null $path Path for view files.
$thissetTheme(string|null $theme): $this
Sets the view theme to use.
string|null $theme Theme name. Use null to remove the current theme.
$thissetVar(string $name, mixed $value = null): $this
Saves a variable for use inside a template.
string $name A string or an array of data.
mixed $value optional Value.
$thissetVars(array<string, mixed> $data, bool $merge = true): $this
Saves view vars for use inside templates.
array<string, mixed> $data Array of data.
bool $merge optional Whether to merge with existing vars, default true.
$thisunserialize(string $data): void
Unserializes the view builder object.
string $data Serialized string.
voidWhether autoLayout should be enabled.
boolThe view class name to use. Can either use plugin notation, a short name or a fully namespaced classname.
string|nullThe helpers to use
arrayThe layout name to render.
string|nullThe layout path to build the view with.
string|nullThe view variables to use
string|nullAdditional options used when constructing the view.
These options array lets you provide custom constructor arguments to application/plugin view classes.
array<string, mixed>The plugin name to use.
string|nullThe template file to render.
string|nullThe subdirectory to the template.
string|nullThe theme name to use.
string|nullView vars
array<string, mixed>
© 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/4.4/class-Cake.View.ViewBuilder.html