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 or not autoLayout should be enabled. 
- 
        $_className protectedstringThe view class name to use. Can either use plugin notation, a short name or a fully namespaced classname. 
- 
        $_helpers protectedarrayThe helpers to use 
- 
        $_layout protectedstringThe layout name to render. 
- 
        $_layoutPath protectedstringThe layout path to build the view with. 
- 
        $_name protectedstringThe view variables to use 
- 
        $_options protectedarrayAdditional options used when constructing the view. 
- 
        $_plugin protectedstringThe plugin name to use. 
- 
        $_template protectedstringThe template file to render. 
- 
        $_templatePath protectedstringThe subdirectory to the template. 
- 
        $_theme protectedstringThe theme name to use. 
Method Summary
- 
          autoLayout() public deprecatedTurns 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() publicUsing the data in the builder, create a view instance. 
- 
          className() public deprecatedGet/set the view classname. 
- 
          createFromArray() publicConfigures a view builder instance from serialized config. 
- 
          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. 
- 
          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 /src/Template/ without the .ctp extension. 
- 
          getTemplatePath() publicGets path for template files. 
- 
          getTheme() publicGets the view theme to use. 
- 
          helpers() public deprecatedThe helpers to use 
- 
          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. 
- 
          layout() public deprecatedGet/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 deprecatedGet/set path for layout files. 
- 
          name() public deprecatedGet/set the view name 
- 
          options() public deprecatedSet additional options for the view. 
- 
          plugin() public deprecatedThe plugin name to use 
- 
          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 /src/Template/Layout without the .ctp extension. 
- 
          setLayoutPath() publicSets path for layout files. 
- 
          setName() publicSets the view name. 
- 
          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 /src/Template/ without the .ctp extension. 
- 
          setTemplatePath() publicSets path for template files. 
- 
          setTheme() publicSets the view theme to use. 
- 
          template() public deprecatedGet/set the name of the view file to render. The name specified is the filename in /src/Template/ without the .ctp extension. 
- 
          templatePath() public deprecatedGet/set path for template files. 
- 
          theme() public deprecatedThe view theme to use. 
- 
          unserialize() publicUnserializes the view builder object. 
Method Detail
autoLayout() ¶ public
autoLayout(bool|null $enable = null): bool|$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|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\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 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|$thisGet/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): $thisConfigures a view builder instance from serialized config.
Parameters
- 
                array$config
- View builder configuration array. 
Returns
$thisConfigured view builder instance.
enableAutoLayout() ¶ 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(): stringGets the name of the layout file to render the view inside of.
Returns
stringgetTemplate() ¶ public
getTemplate(): stringGets the name of the view file to render. The name specified is the
filename in /src/Template/
Returns
stringhelpers() ¶ public
helpers(array|null $helpers = null, bool $merge = true): array|$thisThe 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(): 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.
Returns
arraySerializable array of configuration properties.
layout() ¶ public
layout(string|null $name = null): string|$thisGet/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|$thisGet/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|$thisGet/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|$thisSet 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|null|false $name = null): string|$thisThe 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|$thissetClassName() ¶ public
setClassName(string $name): $thisSets the view classname.
Accepts either a short name (Ajax) a plugin name (MyPlugin.Ajax) or a fully namespaced name (App\View\AppView).
Parameters
- 
                string$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 or not to merge existing data with the new data. 
Returns
$thissetLayout() ¶ public
setLayout(string $name): $thisSets 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$name
- Layout file name to set. 
Returns
$thissetLayoutPath() ¶ public
setLayoutPath(string $path): $thisSets path for layout files.
Parameters
- 
                string$path
- Path for layout files. 
Returns
$thissetName() ¶ public
setName(string $name): $thisSets the view name.
Parameters
- 
                string$name
- The name of the view. 
Returns
$thissetOptions() ¶ public
setOptions(array $options, bool $merge = true): $thisSets 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|null|false $name): $thisSets the plugin name to use.
False to remove current plugin name is deprecated as of 3.4.0. Use directly null instead.
Parameters
- 
                string|null|false$name
- Plugin name. Use null or false to remove the current plugin name. 
Returns
$thissetTemplate() ¶ public
setTemplate(string $name): $thisSets the name of the view file to render. The name specified is the
filename in /src/Template/
Parameters
- 
                string$name
- View file name to set. 
Returns
$thissetTemplatePath() ¶ public
setTemplatePath(string $path): $thisSets path for template files.
Parameters
- 
                string$path
- Path for view files. 
Returns
$thissetTheme() ¶ public
setTheme(string|null|false $theme): $thisSets the view theme to use.
False to remove current theme is deprecated as of 3.4.0. Use directly null instead.
Parameters
- 
                string|null|false$theme
- Theme name. Use null or false to remove the current theme. 
Returns
$thistemplate() ¶ public
template(string|null $name = null): string|$thisGet/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|$thisGet/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|null|false $theme = null): string|$thisThe 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|$thisunserialize() ¶ public
unserialize(string $data): $thisUnserializes 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$_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