CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • AjaxView
  • Cell
  • Helper
  • HelperRegistry
  • JsonView
  • SerializedView
  • StringTemplate
  • View
  • ViewBlock
  • ViewBuilder
  • XmlView

Traits

  • CellTrait
  • StringTemplateTrait
  • ViewVarsTrait

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|null
    Whether or not autoLayout should be enabled.
  • $_className protected
    string|null

    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|false|null
    The layout name to render.
  • $_layoutPath protected
    string|null
    The layout path to build the view with.
  • $_name protected
    string|null
    The view variables to use
  • $_options protected
    array
    Additional options used when constructing the view.
  • $_plugin protected
    string|false|null
    The plugin name to use.
  • $_template protected
    string|null
    The template file to render.
  • $_templatePath protected
    string|null
    The subdirectory to the template.
  • $_theme protected
    string|false|null
    The theme name to use.
  • $_vars protected
    array
    View vars

Method Summary

  • autoLayout() public deprecated

    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 deprecated
    Get/set the view classname.
  • 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 of.
  • getLayoutPath() public
    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.

  • 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.
  • helpers() public deprecated
    The helpers to use
  • 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.

  • layout() public deprecated

    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 deprecated
    Get/set path for layout files.
  • name() public deprecated
    Get/set the view name
  • options() public deprecated
    Set additional options for the view.
  • plugin() public deprecated
    The plugin name to use
  • serialize() public
    Serializes the view builder object.
  • setClassName() public
    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.

  • setLayoutPath() public
    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.

  • 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.
  • template() public deprecated

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

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

Method Detail

autoLayout() public deprecated ¶

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() public ¶

build( array $vars = [] , Cake\Http\ServerRequest $request = null , Cake\Http\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\Http\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() public deprecated ¶

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

disableAutoLayout() public ¶

disableAutoLayout( )

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

$this

enableAutoLayout() 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() public ¶

getClassName( )

Gets the view classname.

Returns
string|null

getHelpers() public ¶

getHelpers( )

Gets the helpers to use.

Returns
array

getLayout() public ¶

getLayout( )

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

Returns
string|false|null

getLayoutPath() public ¶

getLayoutPath( )

Gets path for layout files.

Returns
string|null

getName() public ¶

getName( )

Gets the view name.

Returns
string|null

getOptions() public ¶

getOptions( )

Gets additional options for the view.

Returns
array

getPlugin() public ¶

getPlugin( )

Gets the plugin name to use.

Returns
string|false|null

getTemplate() 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|null

getTemplatePath() public ¶

getTemplatePath( )

Gets path for template files.

Returns
string|null

getTheme() public ¶

getTheme( )

Gets the view theme to use.

Returns
string|false|null

getVar() public ¶

getVar( string $name )

Get view var

Parameters
string $name
Var name
Returns
mixed
The var value or null if unset.

getVars() public ¶

getVars( )

Get all view vars.

Returns
array

hasVar() public ¶

hasVar( string $name )

Check if view var is set.

Parameters
string $name
Var name
Returns
boolean

helpers() public deprecated ¶

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() 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|null

jsonSerialize() 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() public deprecated ¶

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() public deprecated ¶

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() public deprecated ¶

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() public deprecated ¶

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() public deprecated ¶

plugin( string|false|null $name = null )

The plugin name to use

Deprecated
3.4.0 Use setPlugin()/getPlugin() instead.
Parameters
string|false|null $name optional null

Plugin name. If null returns current plugin. Use false to remove the current plugin name.

Returns
string|false|null|Cake\View\ViewBuilder
$this

serialize() public ¶

serialize( )

Serializes the view builder object.

Returns
string
Implementation of
Serializable::serialize()

setClassName() public ¶

setClassName( string|null $name )

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

$this

setHelpers() 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() public ¶

setLayout( string|false|null $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|false|null $name
Layout file name to set.
Returns

$this

setLayoutPath() public ¶

setLayoutPath( string|null $path )

Sets path for layout files.

Parameters
string|null $path
Path for layout files.
Returns

$this

setName() public ¶

setName( string|null $name )

Sets the view name.

Parameters
string|null $name
The name of the view.
Returns

$this

setOptions() 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() public ¶

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

Plugin name. Use null or false to remove the current plugin name.

Returns

$this

setTemplate() public ¶

setTemplate( string|null $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|null $name
View file name to set.
Returns

$this

setTemplatePath() public ¶

setTemplatePath( string|null $path )

Sets path for template files.

Parameters
string|null $path
Path for view files.
Returns

$this

setTheme() public ¶

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

Theme name. Use null or false to remove the current theme.

Returns

$this

setVar() public ¶

setVar( string $name , mixed $value = null )

Saves a variable for use inside a template.

Parameters
string $name
A string or an array of data.
mixed $value optional null
Value.
Returns

$this

setVars() public ¶

setVars( array $data , boolean $merge = true )

Saves view vars for use inside templates.

Parameters
array $data
Array of data.
boolean $merge optional true
Whether to merge with existing vars, default true.
Returns

$this

template() public deprecated ¶

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() public deprecated ¶

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() public deprecated ¶

theme( string|false|null $theme = null )

The view theme to use.

Deprecated
3.4.0 Use setTheme()/getTheme() instead.
Parameters
string|false|null $theme optional null

Theme name. If null returns current theme. Use false to remove the current theme.

Returns
string|false|null|Cake\View\ViewBuilder
$this

unserialize() 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

$_autoLayout ¶

protected boolean|null

Whether or not autoLayout should be enabled.

$_className ¶

protected string|null

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|false|null

The layout name to render.

$_layoutPath ¶

protected string|null

The layout path to build the view with.

$_name ¶

protected string|null

The view variables to use

$_options ¶

protected array

Additional options used when constructing the view.

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

[]

$_plugin ¶

protected string|false|null

The plugin name to use.

$_template ¶

protected string|null

The template file to render.

$_templatePath ¶

protected string|null

The subdirectory to the template.

$_theme ¶

protected string|false|null

The theme name to use.

$_vars ¶

protected array

View vars

[]
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs