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
boolWhether 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|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
array<string, mixed>Additional options used when constructing the view.
 - 
        $_plugin protected
string|nullThe plugin name to use.
 - 
        $_template protected
string|nullThe template file to render.
 - 
        $_templatePath protected
string|nullThe subdirectory to the template.
 - 
        $_theme protected
string|nullThe theme name to use.
 - 
        $_vars protected
array<string, mixed>View vars
 
Method Summary
- 
          
__serialize() public
Magic method used for serializing the view builder object.
 - 
          
__unserialize() public
Magic method used to rebuild the view builder object.
 - 
          
_checkViewVars() protected
Iterates through hash to clean up and normalize.
 - 
          
addHelper() public
Adds a helper to use, overwriting any existing one with that name.
 - 
          
addHelpers() public
Adds helpers to use, overwriting any existing one with that name.
 - 
          
build() public
Using the data in the builder, create a view instance.
 - 
          
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.
 - 
          
getLayoutPath() public
Gets path for layout files.
 - 
          
getName() public
Gets the view name.
 - 
          
getOption() public
Get view option.
 - 
          
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
templates/<SubFolder>/without the .php 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.
 - 
          
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.
 - 
          
setClassName() public
Sets the view classname.
 - 
          
setHelpers() public
Sets the helpers to use, resetting the helpers config.
 - 
          
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
templates/layout/without the .php extension. - 
          
setLayoutPath() public
Sets path for layout files.
 - 
          
setName() public
Sets the view name.
 - 
          
setOption() public
Set view option.
 - 
          
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
templates/<SubFolder>/without the .php 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.
 
Method Detail
__serialize() ¶ public
__serialize(): array
      Magic method used for serializing the view builder object.
Returns
array__unserialize() ¶ public
__unserialize(array<string, mixed> $data): void
      Magic method used to rebuild the view builder object.
Parameters
- 
                
array<string, mixed>$data Data array.
Returns
void_checkViewVars() ¶ protected
_checkViewVars(mixed $item, string $key): void
      Iterates through hash to clean up and normalize.
Parameters
- 
                
mixed$item Reference to the view var value.
- 
                
string$key View var key.
Returns
voidThrows
InvalidArgumentExceptionaddHelper() ¶ public
addHelper(string $helper, array<string, mixed> $options = []): $this
      Adds a helper to use, overwriting any existing one with that name.
Parameters
- 
                
string$helper Helper to use.
- 
                
array<string, mixed>$options optional Options.
Returns
$thisaddHelpers() ¶ public
addHelpers(array $helpers): $this
      Adds helpers to use, overwriting any existing one with that name.
Parameters
- 
                
array$helpers Helpers to use.
Returns
$thisbuild() ¶ public
build(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.
Parameters
- 
                
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.
Returns
Cake\View\ViewThrows
Cake\View\Exception\MissingViewExceptioncreateFromArray() ¶ public
createFromArray(array<string, mixed> $config): $this
      Configures a view builder instance from serialized config.
Parameters
- 
                
array<string, mixed>$config View builder configuration array.
Returns
$thisdisableAutoLayout() ¶ 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|null
      Gets the name of the layout file to render the view inside.
Returns
string|nullgetLayoutPath() ¶ public
getLayoutPath(): string|null
      Gets path for layout files.
Returns
string|nullgetOption() ¶ public
getOption(string $name): mixed
      Get view option.
Parameters
- 
                
string$name The name of the option.
Returns
mixedgetOptions() ¶ public
getOptions(): array<string, mixed>
      Gets additional options for the view.
Returns
array<string, mixed>getTemplate() ¶ public
getTemplate(): string|null
      Gets the name of the view file to render. The name specified is the
filename in templates/<SubFolder>/ without the .php extension.
Returns
string|nullgetTemplatePath() ¶ public
getTemplatePath(): string|null
      Gets path for template files.
Returns
string|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
boolisAutoLayoutEnabled() ¶ public
isAutoLayoutEnabled(): 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.
Returns
booljsonSerialize() ¶ public
jsonSerialize(): 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:
- ORM\Query executed and stored as result set
 - SimpleXMLElements stored as associative array
 - Exceptions stored as strings
 - Resources, \Closure and \PDO are not supported.
 
Returns
arraySerializable array of configuration properties.
setClassName() ¶ 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): $this
      Sets the helpers to use, resetting the helpers config.
Parameters
- 
                
array$helpers Helpers to use.
Returns
$thissetLayout() ¶ public
setLayout(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.
Parameters
- 
                
string|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, or null to remove the current name.
Returns
$thissetOption() ¶ public
setOption(string $name, mixed $value): $this
      Set view option.
Parameters
- 
                
string$name The name of the option.
- 
                
mixed$value Value to set.
Returns
$thissetOptions() ¶ public
setOptions(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.
Parameters
- 
                
array<string, mixed>$options An array of options.
- 
                
bool$merge optional Whether to merge existing data with the new data.
Returns
$thissetPlugin() ¶ public
setPlugin(string|null $name): $this
      Sets the plugin name to use.
Parameters
- 
                
string|null$name Plugin name. Use null 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 templates/<SubFolder>/ without the .php extension.
Parameters
- 
                
string|null$name View file name to set, or null to remove the template name.
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|null $theme): $this
      Sets the view theme to use.
Parameters
- 
                
string|null$theme Theme name. Use null 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<string, mixed> $data, bool $merge = true): $this
      Saves view vars for use inside templates.
Parameters
- 
                
array<string, mixed>$data Array of data.
- 
                
bool$merge optional Whether to merge with existing vars, default true.
Returns
$thisProperty 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.
These options array lets you provide custom constructor arguments to application/plugin view classes.
Type
array<string, mixed>