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 protectedboolWhether autoLayout should be enabled. 
- 
        $_className protectedstring|nullThe view class name to use. Can either use plugin notation, a short name or a fully namespaced classname. 
- 
        $_helpers protectedarrayThe helpers to use 
- 
        $_layout protectedstring|nullThe layout name to render. 
- 
        $_layoutPath protectedstring|nullThe layout path to build the view with. 
- 
        $_name protectedstring|nullThe view variables to use 
- 
        $_options protectedarray<string, mixed>Additional options used when constructing the view. 
- 
        $_plugin protectedstring|nullThe plugin name to use. 
- 
        $_template protectedstring|nullThe template file to render. 
- 
        $_templatePath protectedstring|nullThe subdirectory to the template. 
- 
        $_theme protectedstring|nullThe theme name to use. 
- 
        $_vars protectedarray<string, mixed>View vars 
Method Summary
- 
          __serialize() publicMagic method used for serializing the view builder object. 
- 
          __unserialize() publicMagic method used to rebuild the view builder object. 
- 
          _checkViewVars() protectedIterates through hash to clean up and normalize. 
- 
          addHelper() publicAdds a helper to use. 
- 
          addHelpers() publicAdds helpers to use by merging with existing ones. 
- 
          build() publicUsing the data in the builder, create a view instance. 
- 
          createFromArray() publicConfigures a view builder instance from serialized config. 
- 
          disableAutoLayout() publicTurns off CakePHP's conventional mode of applying layout files. 
- 
          enableAutoLayout() publicTurns 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() publicGets the view classname. 
- 
          getHelpers() publicGets the helpers to use. 
- 
          getLayout() publicGets the name of the layout file to render the view inside of. 
- 
          getLayoutPath() publicGets path for layout files. 
- 
          getName() publicGets the view name. 
- 
          getOption() publicGet view option. 
- 
          getOptions() publicGets additional options for the view. 
- 
          getPlugin() publicGets the plugin name to use. 
- 
          getTemplate() publicGets the name of the view file to render. The name specified is the filename in templates/<SubFolder>/without the .php extension.
- 
          getTemplatePath() publicGets path for template files. 
- 
          getTheme() publicGets the view theme to use. 
- 
          getVar() publicGet view var 
- 
          getVars() publicGet all view vars. 
- 
          hasVar() publicCheck if view var is set. 
- 
          isAutoLayoutEnabled() publicReturns if CakePHP's conventional mode of applying layout files is enabled. Disabled means that layouts will not be automatically applied to rendered views. 
- 
          jsonSerialize() publicSerializes the view builder object to a value that can be natively serialized and re-used to clone this builder instance. 
- 
          serialize() publicSerializes the view builder object. 
- 
          setClassName() publicSets the view classname. 
- 
          setHelpers() publicSets the helpers to use. 
- 
          setLayout() publicSets 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() publicSets path for layout files. 
- 
          setName() publicSets the view name. 
- 
          setOption() publicSet view option. 
- 
          setOptions() publicSets additional options for the view. 
- 
          setPlugin() publicSets the plugin name to use. 
- 
          setTemplate() publicSets the name of the view file to render. The name specified is the filename in templates/<SubFolder>/without the .php extension.
- 
          setTemplatePath() publicSets path for template files. 
- 
          setTheme() publicSets the view theme to use. 
- 
          setVar() publicSaves a variable for use inside a template. 
- 
          setVars() publicSaves view vars for use inside templates. 
- 
          unserialize() publicUnserializes the view builder object. 
Method Detail
__serialize() ¶ public
__serialize(): arrayMagic method used for serializing the view builder object.
Returns
array__unserialize() ¶ public
__unserialize(array<string, mixed> $data): voidMagic method used to rebuild the view builder object.
Parameters
- 
                array<string, mixed>$data
- Data array. 
Returns
void_checkViewVars() ¶ protected
_checkViewVars(mixed $item, string $key): voidIterates through hash to clean up and normalize.
Parameters
- 
                mixed$item
- Reference to the view var value. 
- 
                string$key
- View var key. 
Returns
voidThrows
RuntimeExceptionaddHelper() ¶ public
addHelper(string $helper, array<string, mixed> $options = []): $thisAdds a helper to use.
Parameters
- 
                string$helper
- Helper to use. 
- 
                array<string, mixed>$options optional
- Options. 
Returns
$thisaddHelpers() ¶ public
addHelpers(array $helpers): $thisAdds helpers to use by merging with existing ones.
Parameters
- 
                array$helpers
- Helpers to use. 
Returns
$thisbuild() ¶ public
build(array<string, mixed> $vars = [], Cake\Http\ServerRequest|null $request = null, Cake\Http\Response|null $response = null, Cake\Event\EventManagerInterface|null $events = null): Cake\View\ViewUsing 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
- 
                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. 
Returns
Cake\View\ViewThrows
Cake\View\Exception\MissingViewExceptioncreateFromArray() ¶ public
createFromArray(array<string, mixed> $config): $thisConfigures a view builder instance from serialized config.
Parameters
- 
                array<string, mixed>$config
- View builder configuration array. 
Returns
$thisdisableAutoLayout() ¶ public
disableAutoLayout(): $thisTurns 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): $thisTurns 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|nullGets the name of the layout file to render the view inside of.
Returns
string|nullgetLayoutPath() ¶ public
getLayoutPath(): string|nullGets path for layout files.
Returns
string|nullgetOption() ¶ public
getOption(string $name): mixedGet 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|nullGets 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|nullGets path for template files.
Returns
string|nullgetVar() ¶ public
getVar(string $name): mixedGet view var
Parameters
- 
                string$name
- Var name 
Returns
mixedThe var value or null if unset.
hasVar() ¶ public
hasVar(string $name): boolCheck if view var is set.
Parameters
- 
                string$name
- Var name 
Returns
boolisAutoLayoutEnabled() ¶ public
isAutoLayoutEnabled(): boolReturns 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(): arraySerializes 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 resultset
- 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): $thisSets 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): $thisSets the helpers to use.
Parameters
- 
                array$helpers
- Helpers to use. 
- 
                bool$merge optional
- Whether to merge existing data with the new data. 
Returns
$thissetLayout() ¶ public
setLayout(string|null $name): $thisSets 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): $thisSets path for layout files.
Parameters
- 
                string|null$path
- Path for layout files. 
Returns
$thissetName() ¶ public
setName(string|null $name): $thisSets 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): $thisSet 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): $thisSets 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): $thisSets 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): $thisSets 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): $thisSets path for template files.
Parameters
- 
                string|null$path
- Path for view files. 
Returns
$thissetTheme() ¶ public
setTheme(string|null $theme): $thisSets 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): $thisSaves 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): $thisSaves 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
$thisunserialize() ¶ public
unserialize(string $data): voidUnserializes the view builder object.
Parameters
- 
                string$data
- Serialized string. 
Returns
voidProperty 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>