On this page
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().
- Cake\View\ViewBuilder implements JsonSerializable, Serializable
Properties summary
-
$_autoLayoutprotectedWhether or not autoLayout should be enabled.boolean -
$_classNameprotectedstringThe view class name to use. Can either use plugin notation, a short name or a fully namespaced classname.
-
$_helpersprotectedThe helpers to usearray -
$_layoutprotectedThe layout name to render.string -
$_layoutPathprotectedThe layout path to build the view with.string -
$_nameprotectedThe view variables to usestring -
$_optionsprotectedAdditional options used when constructing the view.array -
$_pluginprotectedThe plugin name to use.string -
$_templateprotectedThe template file to render.string -
$_templatePathprotectedThe subdirectory to the template.string -
$_themeprotectedThe theme name to use.string
Method Summary
-
autoLayout() 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.
-
build() publicUsing the data in the builder, create a view instance.
-
className() publicGet/set the view classname.
-
createFromArray() publicConfigures a view builder instance from serialized config.
-
helpers() publicThe helpers to use
-
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
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() publicGet/set path for layout files.
-
name() publicGet/set the view name
-
options() publicSet additional options for the view.
-
plugin() publicThe plugin name to use
-
serialize() publicSerializes the view builder object.
-
template() public
Get/set the name of the view file to render. The name specified is the filename in /src/Template/
without the .ctp extension. -
templatePath() publicGet/set path for template files.
-
theme() publicThe view theme to use.
-
unserialize() publicUnserializes the view builder object.
Method Detail
autoLayout()source public
autoLayout( boolean|null $autoLayout null )
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
-
boolean|null
$autoLayoutoptional null - Boolean to turn on/off. If null returns current value.
Returns
boolean|Cake\View\ViewBuilder$this
build()source public
build( array $vars [] , Cake\Network\Request $request null , Cake\Network\Response $response null , Cake\Event\EventManager $events null )
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
$varsoptional [] - The view variables/context to use.
Cake\Network\Request$requestoptional null- The request to use.
Cake\Network\Response$responseoptional null- The response to use.
Cake\Event\EventManager$eventsoptional null- The event manager to use.
Returns
Cake\View\ViewThrows
Cake\View\Exception\MissingViewExceptionclassName()source public
className( string|null $name null )
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
$nameoptional null -
The class name for the view. Can be a plugin.class name reference, a short alias, or a fully namespaced name.
Returns
array|Cake\View\ViewBuilder$this
createFromArray()source public
createFromArray( array $config )
Configures a view builder instance from serialized config.
Parameters
-
array
$config - View builder configuration array.
Returns
$this Configured view builder instance.
helpers()source public
helpers( array $helpers null , boolean $merge true )
The helpers to use
Parameters
-
array
$helpersoptional null - Helpers to use.
-
boolean
$mergeoptional true - Whether or not to merge existing data with the new data.
Returns
array|Cake\View\ViewBuilder$this
jsonSerialize()source public
jsonSerialize( )
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.
Implementation of
JsonSerializable::jsonSerialize()
layout()source public
layout( string|null $name null )
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
$nameoptional null - Layout file name to set. If null returns current name.
Returns
string|Cake\View\ViewBuilder$this
layoutPath()source public
layoutPath( string|null $path null )
Get/set path for layout files.
Parameters
-
string|null
$pathoptional null - Path for layout files. If null returns current path.
Returns
string|Cake\View\ViewBuilder$this
name()source public
name( string|null $name null )
Get/set the view name
Parameters
-
string|null
$nameoptional null - The name of the view
Returns
array|Cake\View\ViewBuilder$this
options()source public
options( array $options null , boolean $merge true )
Set additional options for the view.
This lets you provide custom constructor arguments to application/plugin view classes.
Parameters
-
array
$optionsoptional null - Either an array of options or null to get current options.
-
boolean
$mergeoptional true - Whether or not to merge existing data with the new data.
Returns
array|Cake\View\ViewBuilder$this
plugin()source public
plugin( string|null|false $name null )
The plugin name to use
Parameters
-
string|null|false
$nameoptional null -
Plugin name. If null returns current plugin. Use false to remove the current plugin name.
Returns
string|Cake\View\ViewBuilder$this
serialize()source public
serialize( )
Serializes the view builder object.
Returns
stringImplementation of
Serializable::serialize()
template()source public
template( string|null $name null )
Get/set the name of the view file to render. The name specified is the filename in /src/Template/
Parameters
-
string|null
$nameoptional null - View file name to set. If null returns current name.
Returns
string|Cake\View\ViewBuilder$this
templatePath()source public
templatePath( string|null $path null )
Get/set path for template files.
Parameters
-
string|null
$pathoptional null - Path for view files. If null returns current path.
Returns
string|Cake\View\ViewBuilder$this
theme()source public
theme( string|null|false $theme null )
The view theme to use.
Parameters
-
string|null|false
$themeoptional null -
Theme name. If null returns current theme. Use false to remove the current theme.
Returns
string|Cake\View\ViewBuilder$this
unserialize()source public
unserialize( string $data )
Unserializes the view builder object.
Parameters
-
string
$data - Serialized string.
Returns
$this Configured view builder instance.
Implementation of
Serializable::unserialize()
Properties detail
$_classNamesource
protected string
The view class name to use. Can either use plugin notation, a short name or a fully namespaced classname.
$_optionssource
protected array
Additional options used when constructing the view.
This options array lets you provide custom constructor arguments to application/plugin view classes.
[]
© 2005–2016 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.
http://api.cakephp.org/3.2/class-Cake.View.ViewBuilder.html