W3cubDocs

/CakePHP 3.4

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
Namespace: Cake\View
Location: View/ViewBuilder.php

Properties summary

  • $_autoLayout protected
    boolean
    Whether or not autoLayout should be enabled.
  • $_className protected
    string

    The view class name to use. Can either use plugin notation, a short name or a fully namespaced classname.

  • $_helpers protected
    array
    The helpers to use
  • $_layout protected
    string
    The layout name to render.
  • $_layoutPath protected
    string
    The layout path to build the view with.
  • $_name protected
    string
    The view variables to use
  • $_options protected
    array
    Additional options used when constructing the view.
  • $_plugin protected
    string
    The plugin name to use.
  • $_template protected
    string
    The template file to render.
  • $_templatePath protected
    string
    The subdirectory to the template.
  • $_theme protected
    string
    The theme name to use.

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() public
    Using the data in the builder, create a view instance.
  • className() public
    Get/set the view classname.
  • Configures a view builder instance from serialized config.
  • 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.
  • getHelpers() public
    Gets the helpers to use.
  • getLayout() public
    Gets the name of the layout file to render the view inside of.
  • Gets path for layout files.
  • getName() public
    Gets the view name.
  • 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 /src/Template/ without the .ctp extension.

  • Gets path for template files.
  • getTheme() public
    Gets the view theme to use.
  • helpers() public
    The helpers to use
  • 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.

  • 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() public
    Get/set path for layout files.
  • name() public
    Get/set the view name
  • options() public
    Set additional options for the view.
  • plugin() public
    The plugin name to use
  • serialize() public
    Serializes the view builder object.
  • Sets the view classname.
  • setHelpers() public
    Sets the helpers to use.
  • 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 /src/Template/Layout without the .ctp extension.

  • Sets path for layout files.
  • setName() public
    Sets the view name.
  • 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 /src/Template/ without the .ctp extension.

  • Sets path for template files.
  • setTheme() public
    Sets the view theme to use.
  • 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.

  • Get/set path for template files.
  • theme() public
    The view theme to use.
  • unserialize() public
    Unserializes the view builder object.

Method Detail

autoLayout()source public

autoLayout( boolean|null $enable 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.

Deprecated

3.4.0 Use enableAutoLayout()/isAutoLayoutEnabled() instead.

Parameters

boolean|null $enable optional null
Boolean to turn on/off. If null returns current value.

Returns

boolean|Cake\View\ViewBuilder
$this

build()source public

build( array $vars [] , Cake\Http\ServerRequest $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 $vars optional []
The view variables/context to use.
Cake\Http\ServerRequest $request optional null
The request to use.
Cake\Network\Response $response optional null
The response to use.
Cake\Event\EventManager $events optional null
The event manager to use.

Returns

Cake\View\View

Throws

Cake\View\Exception\MissingViewException

className()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).

Deprecated

3.4.0 Use setClassName()/getClassName() instead.

Parameters

string|null $name optional null

The class name for the view. Can be a plugin.class name reference, a short alias, or a fully namespaced name.

Returns

string|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.

enableAutoLayout()source public

enableAutoLayout( boolean $enable true )

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 $enable optional true
Boolean to turn on/off.

Returns


$this

getClassName()source public

getClassName( )

Gets the view classname.

Returns

string

getHelpers()source public

getHelpers( )

Gets the helpers to use.

Returns

array

getLayout()source public

getLayout( )

Gets the name of the layout file to render the view inside of.

Returns

string

getLayoutPath()source public

getLayoutPath( )

Gets path for layout files.

Returns

string

getName()source public

getName( )

Gets the view name.

Returns

string

getOptions()source public

getOptions( )

Gets additional options for the view.

Returns

array

getPlugin()source public

getPlugin( )

Gets the plugin name to use.

Returns

string

getTemplate()source public

getTemplate( )

Gets the name of the view file to render. The name specified is the filename in /src/Template/ without the .ctp extension.

Returns

string

getTemplatePath()source public

getTemplatePath( )

Gets path for template files.

Returns

string

getTheme()source public

getTheme( )

Gets the view theme to use.

Returns

string

helpers()source public

helpers( array $helpers null , boolean $merge true )

The helpers to use

Deprecated

3.4.0 Use setHelpers()/getHelpers() instead.

Parameters

array $helpers optional null
Helpers to use.
boolean $merge optional true
Whether or not to merge existing data with the new data.

Returns

array|Cake\View\ViewBuilder
$this

isAutoLayoutEnabled()source public

isAutoLayoutEnabled( )

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

boolean

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

array
Serializable 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.

Deprecated

3.4.0 Use setLayout()/getLayout() instead.

Parameters

string|null $name optional 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.

Deprecated

3.4.0 Use setLayoutPath()/getLayoutPath() instead.

Parameters

string|null $path optional 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

Deprecated

3.4.0 Use setName()/getName() instead.

Parameters

string|null $name optional null
The name of the view

Returns

string|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.

Deprecated

3.4.0 Use setOptions()/getOptions() instead.

Parameters

array $options optional null
Either an array of options or null to get current options.
boolean $merge optional 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

Deprecated

3.4.0 Use setPlugin()/getPlugin() instead.

Parameters

string|null|false $name optional 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

string

Implementation of

Serializable::serialize()

setClassName()source public

setClassName( string $name )

Sets 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


$this

setHelpers()source public

setHelpers( array $helpers , boolean $merge true )

Sets the helpers to use.

Parameters

array $helpers
Helpers to use.
boolean $merge optional true
Whether or not to merge existing data with the new data.

Returns


$this

setLayout()source public

setLayout( string $name )

Sets 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


$this

setLayoutPath()source public

setLayoutPath( string $path )

Sets path for layout files.

Parameters

string $path
Path for layout files.

Returns


$this

setName()source public

setName( string $name )

Sets the view name.

Parameters

string $name
The name of the view.

Returns


$this

setOptions()source public

setOptions( array $options , boolean $merge true )

Sets additional options for the view.

This lets you provide custom constructor arguments to application/plugin view classes.

Parameters

array $options
An array of options.
boolean $merge optional true
Whether or not to merge existing data with the new data.

Returns


$this

setPlugin()source public

setPlugin( string|null|false $name )

Sets 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


$this

setTemplate()source public

setTemplate( string $name )

Sets the name of the view file to render. The name specified is the filename in /src/Template/ without the .ctp extension.

Parameters

string $name
View file name to set.

Returns


$this

setTemplatePath()source public

setTemplatePath( string $path )

Sets path for template files.

Parameters

string $path
Path for view files.

Returns


$this

setTheme()source public

setTheme( string|null|false $theme )

Sets 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


$this

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/ without the .ctp extension.

Deprecated

3.4.0 Use setTemplate()/getTemplate()

Parameters

string|null $name optional 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.

Deprecated

3.4.0 Use setTemplatePath()/getTemplatePath() instead.

Parameters

string|null $path optional 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.

Deprecated

3.4.0 Use setTheme()/getTheme() instead.

Parameters

string|null|false $theme optional 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

$_autoLayoutsource

protected boolean

Whether or not autoLayout should be enabled.

$_classNamesource

protected string

The view class name to use. Can either use plugin notation, a short name or a fully namespaced classname.

$_helperssource

protected array

The helpers to use

[]

$_layoutsource

protected string

The layout name to render.

$_layoutPathsource

protected string

The layout path to build the view with.

$_namesource

protected string

The view variables to use

$_optionssource

protected array

Additional options used when constructing the view.

This options array lets you provide custom constructor arguments to application/plugin view classes.

[]

$_pluginsource

protected string

The plugin name to use.

$_templatesource

protected string

The template file to render.

$_templatePathsource

protected string

The subdirectory to the template.

$_themesource

protected string

The theme name to use.

© 2005–2017 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/3.4/class-Cake.View.ViewBuilder.html