CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.5 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.5
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 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

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget

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

Namespace: Cake\View

Property Summary

  • $_autoLayout protected
    bool

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

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

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

  • 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

autoLayout(bool|null $enable = null): bool|$this

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
bool|null $enable optional

Boolean to turn on/off. If null returns current value.

Returns
bool|$this

build() ¶ public

build(array $vars = [], Cake\Http\ServerRequest|null $request = null, Cake\Http\Response|null $response = null, Cake\Event\EventManager|null $events = null): Cake\View\View

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|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\View
Throws
Cake\View\Exception\MissingViewException

className() ¶ public

className(string|null $name = null): string|$this

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 $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|$this

createFromArray() ¶ public

createFromArray(array $config): $this

Configures a view builder instance from serialized config.

Parameters
array $config

View builder configuration array.

Returns
$this

enableAutoLayout() ¶ public

enableAutoLayout(bool $enable = true): $this

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
bool $enable optional

Boolean to turn on/off.

Returns
$this

getClassName() ¶ public

getClassName(): string

Gets the view classname.

Returns
string

getHelpers() ¶ public

getHelpers(): array

Gets the helpers to use.

Returns
array

getLayout() ¶ public

getLayout(): string

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

Returns
string

getLayoutPath() ¶ public

getLayoutPath(): string

Gets path for layout files.

Returns
string

getName() ¶ public

getName(): string

Gets the view name.

Returns
string

getOptions() ¶ public

getOptions(): array

Gets additional options for the view.

Returns
array

getPlugin() ¶ public

getPlugin(): string

Gets the plugin name to use.

Returns
string

getTemplate() ¶ public

getTemplate(): string

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

getTemplatePath(): string

Gets path for template files.

Returns
string

getTheme() ¶ public

getTheme(): string

Gets the view theme to use.

Returns
string

helpers() ¶ public

helpers(array|null $helpers = null, bool $merge = true): array|$this

The 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|$this

isAutoLayoutEnabled() ¶ public

isAutoLayoutEnabled(): bool

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
bool

jsonSerialize() ¶ public

jsonSerialize(): array

Serializes the view builder object to a value that can be natively serialized and re-used to clone this builder instance.

Returns
array

layout() ¶ public

layout(string|null $name = null): string|$this

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 $name optional

Layout file name to set. If null returns current name.

Returns
string|$this

layoutPath() ¶ public

layoutPath(string|null $path = null): string|$this

Get/set path for layout files.

Parameters
string|null $path optional

Path for layout files. If null returns current path.

Returns
string|$this

name() ¶ public

name(string|null $name = null): string|$this

Get/set the view name

Parameters
string|null $name optional

The name of the view

Returns
string|$this

options() ¶ public

options(array|null $options = null, bool $merge = true): array|$this

Set 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|$this

plugin() ¶ public

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

The 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|$this

serialize() ¶ public

serialize(): string

Serializes the view builder object.

Returns
string

setClassName() ¶ public

setClassName(string $name): $this

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

setHelpers(array $helpers, bool $merge = true): $this

Sets 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
$this

setLayout() ¶ public

setLayout(string $name): $this

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

setLayoutPath(string $path): $this

Sets path for layout files.

Parameters
string $path

Path for layout files.

Returns
$this

setName() ¶ public

setName(string $name): $this

Sets the view name.

Parameters
string $name

The name of the view.

Returns
$this

setOptions() ¶ public

setOptions(array $options, bool $merge = true): $this

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.

bool $merge optional

Whether or not to merge existing data with the new data.

Returns
$this

setPlugin() ¶ public

setPlugin(string|null|false $name): $this

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

setTemplate(string $name): $this

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

setTemplatePath(string $path): $this

Sets path for template files.

Parameters
string $path

Path for view files.

Returns
$this

setTheme() ¶ public

setTheme(string|null|false $theme): $this

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

template(string|null $name = null): string|$this

Get/set 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 optional

View file name to set. If null returns current name.

Returns
string|$this

templatePath() ¶ public

templatePath(string|null $path = null): string|$this

Get/set path for template files.

Parameters
string|null $path optional

Path for view files. If null returns current path.

Returns
string|$this

theme() ¶ public

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

The 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|$this

unserialize() ¶ public

unserialize(string $data): $this

Unserializes the view builder object.

Parameters
string $data

Serialized string.

Returns
$this

Property Detail

$_autoLayout ¶ protected

Whether or not autoLayout should be enabled.

Type
bool

$_className ¶ protected

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

Type
string

$_helpers ¶ protected

The helpers to use

Type
array

$_layout ¶ protected

The layout name to render.

Type
string

$_layoutPath ¶ protected

The layout path to build the view with.

Type
string

$_name ¶ protected

The view variables to use

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

$_plugin ¶ protected

The plugin name to use.

Type
string

$_template ¶ protected

The template file to render.

Type
string

$_templatePath ¶ protected

The subdirectory to the template.

Type
string

$_theme ¶ protected

The theme name to use.

Type
string
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs