A view class that is used for AJAX responses.
Currently only switches the default layout and sets the response type - which just maps to text/html by default.
string
'templates'
string
'plugin'
string
'element'
string
'layout'
string
'template'
\Cake\View\ViewBlock
ViewBlock instance.
\Cake\View\Helper\BreadcrumbsHelper
\Cake\View\Helper\FlashHelper
\Cake\View\Helper\FormHelper
\Cake\View\Helper\HtmlHelper
\Cake\View\Helper\NumberHelper
\Cake\View\Helper\PaginatorHelper
\Cake\View\Helper\TextHelper
\Cake\View\Helper\TimeHelper
\Cake\View\Helper\UrlHelper
array
Runtime config
bool
Whether the config property has already been configured with defaults
string
The currently rendering view file. Used for resolving parent files.
string
Currently rendering an element. Used for finding parent fragments for elements.
string[]
Default custom config options.
string
Default class name for new event objects.
\Cake\Event\EventManagerInterface
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
string
File extension. Defaults to ".php".
\Cake\View\HelperRegistry
Helpers collection
string[]
The names of views and their parents used with View::extend();
string[]
List of variables to collect from the associated controller.
string[]
Holds an array of paths.
string[][]
Holds an array of plugin paths.
string[]
Content stack, used for nested templates that all use View::extend();
string
ViewBlock class.
bool
Turns on or off CakePHP's conventional mode of applying layout files. On by default.
string
The Cache configuration View will use to store cached elements. Changing this will change the default configuration elements are stored under. You can also choose a cache config per element.
array
An array of names of built-in helpers to include.
string
The name of the layout file to render the template inside of. The name specified is the filename of the layout in templates/layout/
without the .php extension.
string
The name of the layouts subfolder containing layouts for this View.
string
Name of the controller that created the View if any.
string|null
The name of the plugin.
\Cake\Http\ServerRequest
An instance of a \Cake\Http\ServerRequest object that contains information about the current request.
\Cake\Http\Response
Reference to the Response object
string
Sub-directory for this template file. This is often used for extension based routing.
string
The name of the template file to render. The name specified is the filename in templates/<SubFolder>/
without the .php extension.
string
The name of the subfolder containing templates for this View.
string|null
The view theme to use.
array
An array of variables
Check that a view file path does not go outside of the defined template paths.
Find all sub templates path, based on $basePath If a prefix is defined in the current request, this method will prepend the prefixed template path to the $basePath, cascading up in case the prefix is nested.
Change the name of a view template file into underscored format.
Renders and returns output for given template filename with its array of data. Handles parent/extended templates.
Renders an element and fires the before and afterRender callbacks for it and writes to the cache if a cache is used
Merge provided config with existing config. Unlike config()
which does a recursive merge for nested keys, this method does a simple merge.
Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string.
Provides template or element extension/inheritance. Templates can extends a parent template and populate blocks in the parent template.
Get the name of the template file to render. The name specified is the filename in templates/<SubFolder>/
without the .php extension.
Returns if CakePHP's conventional mode of applying layout files is enabled.
Convenience method to write a message to Log. See Log::write() for more information on writing to logs.
Sets the request objects and configures a number of controller properties based on the contents of the request. The properties that get set are:
Set the name of the template file to render. The name specified is the filename in templates/<SubFolder>/
without the .php extension.
__construct(?\Cake\Http\ServerRequest $request, ?\Cake\Http\Response $response, ?\Cake\Event\EventManager $eventManager, array $viewOptions)
Constructor
\Cake\Http\ServerRequest|null
$request optional Request instance.
\Cake\Http\Response|null
$response optional Response instance.
\Cake\Event\EventManager|null
$eventManager optional Event manager instance.
array
$viewOptions optional View options. See View::$_passedVars for list of options which get set as class properties.
__get(string $name)
Magic accessor for helpers.
string
$name Name of the attribute to get.
mixed
_checkFilePath(string $file, string $path)
Check that a view file path does not go outside of the defined template paths.
Only paths that contain ..
will be checked, as they are the ones most likely to have the ability to resolve to files outside of the template paths.
string
$file The path to the template file.
string
$path Base path that $file should be inside of.
string
The file path
InvalidArgumentException
_configDelete(string $key)
Deletes a single config key.
string
$key Key to delete.
Cake\Core\Exception\Exception
_configRead(?string $key)
Reads a config key.
string|null
$key Key to read.
mixed
_configWrite(mixed $key, mixed $value, mixed $merge)
Writes a config key.
string|array
$key Key to write to.
mixed
$value Value to write.
bool|string
$merge optional True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.
Cake\Core\Exception\Exception
_createCell(string $className, string $action, ?string $plugin, array $options)
Create and configure the cell instance.
string
$className The cell classname.
string
$action The action name.
string|null
$plugin The plugin name.
array
$options The constructor options for the cell.
\Cake\View\Cell
_elementCache(string $name, array $data, array $options)
Generate the cache configuration options for an element.
string
$name Element name
array
$data Data
array
$options Element options
array
Element Cache configuration.
_evaluate(string $templateFile, array $dataForView)
Sandbox method to evaluate a template / view script in.
string
$templateFile Filename of the template.
array
$dataForView Data to include in rendered view.
string
Rendered output
_getElementFileName(string $name, bool $pluginCheck)
Finds an element filename, returns false on failure.
string
$name The name of the element to find.
bool
$pluginCheck optional string|false
Either a string to the element filename or false when one can't be found.
_getLayoutFileName(?string $name)
Returns layout filename for this template as a string.
string|null
$name optional The name of the layout to find.
string
Filename for layout file.
Cake\View\Exception\MissingLayoutException
RuntimeException
_getSubPaths(string $basePath)
Find all sub templates path, based on $basePath If a prefix is defined in the current request, this method will prepend the prefixed template path to the $basePath, cascading up in case the prefix is nested.
This is essentially used to find prefixed template paths for elements and layouts.
string
$basePath Base path on which to get the prefixed one.
string[]
Array with all the templates paths.
_getTemplateFileName(?string $name)
Returns filename of given action's template file as a string.
CamelCased action names will be under_scored by default. This means that you can have LongActionNames that refer to long_action_names.php templates. You can change the inflection rule by overriding _inflectTemplateFileName.
string|null
$name optional Controller action to find template filename for
string
Template filename
Cake\View\Exception\MissingTemplateException
RuntimeException
_inflectTemplateFileName(string $name)
Change the name of a view template file into underscored format.
string
$name Name of file which should be inflected.
string
File name after conversion
_paths(?string $plugin, bool $cached)
Return all possible paths to find view files in order
string|null
$plugin optional Optional plugin name to scan for view files.
bool
$cached optional Set to false to force a refresh of view paths. Default true.
string[]
paths
_render(string $templateFile, array $data)
Renders and returns output for given template filename with its array of data. Handles parent/extended templates.
string
$templateFile Filename of the template
array
$data optional Data to include in rendered view. If empty the current View::$viewVars will be used.
string
Rendered output
LogicException
_renderElement(string $file, array $data, array $options)
Renders an element and fires the before and afterRender callbacks for it and writes to the cache if a cache is used
string
$file Element file path
array
$data Data to render
array
$options Element options
string
append(string $name, mixed $value)
Append to an existing or new block.
Appending to a new block will create the block.
string
$name Name of the block
mixed
$value optional The content for the block. Value will be type cast to string.
$this
assign(string $name, mixed $value)
Set the content for a block. This will overwrite any existing content.
string
$name Name of the block
mixed
$value The content for the block. Value will be type cast to string.
$this
blocks()
Get the names of all the existing blocks.
string[]
An array containing the blocks.
cache(callable $block, array $options)
Create a cached block of view logic.
This allows you to cache a block of view output into the cache defined in elementCache
.
This method will attempt to read the cache first. If the cache is empty, the $block will be run and the output stored.
callable
$block The block of code that you want to cache the output of.
array
$options optional The options defining the cache key etc.
string
The rendered content.
RuntimeException
cell(string $cell, array $data, array $options)
Renders the given cell.
Example:
// Taxonomy\View\Cell\TagCloudCell::smallList() $cell = $this->cell('Taxonomy.TagCloud::smallList', ['limit' => 10]); // App\View\Cell\TagCloudCell::smallList() $cell = $this->cell('TagCloud::smallList', ['limit' => 10]);
The display
action will be used by default when no action is provided:
// Taxonomy\View\Cell\TagCloudCell::display() $cell = $this->cell('Taxonomy.TagCloud');
Cells are not rendered until they are echoed.
string
$cell You must indicate cell name, and optionally a cell action. e.g.: TagCloud::smallList
will invoke View\Cell\TagCloudCell::smallList()
, display
action will be invoked by default when none is provided.
array
$data optional Additional arguments for cell method. e.g.: cell('TagCloud::smallList', ['a1' => 'v1', 'a2' => 'v2'])
maps to View\Cell\TagCloud::smallList(v1, v2)
array
$options optional Options for Cell's constructor
\Cake\View\Cell
The cell instance
Cake\View\Exception\MissingCellException
BadMethodCallException
configShallow(mixed $key, mixed $value)
Merge provided config with existing config. Unlike config()
which does a recursive merge for nested keys, this method does a simple merge.
Setting a specific value:
$this->configShallow('key', $value);
Setting a nested value:
$this->configShallow('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->configShallow(['one' => 'value', 'another' => 'value']);
string|array
$key The key to set, or a complete array of configs.
mixed|null
$value optional The value to set.
$this
disableAutoLayout()
Turns off CakePHP's conventional mode of applying layout files.
Layouts will not be automatically applied to rendered views.
$this
dispatchEvent(string $name, ?array $data, ?object $subject)
Wrapper for creating and dispatching events.
Returns a dispatched event.
string
$name Name of the event.
array|null
$data optional Any value you wish to be transported with this event to it can be read by listeners.
object|null
$subject optional The object that this event applies to ($this by default).
\Cake\Event\EventInterface
element(string $name, array $data, array $options)
Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string.
This realizes the concept of Elements, (or "partial layouts") and the $params array is used to send data to be used in the element. Elements can be cached improving performance by using the cache
option.
string
$name Name of template file in the templates/element/
folder, or MyPlugin.template
to use the template element from MyPlugin. If the element is not found in the plugin, the normal view path cascade will be searched.
array
$data optional Array of data to be made available to the rendered view (i.e. the Element)
array
$options optional Array of options. Possible keys are:
cache
- Can either be true
, to enable caching using the config in View::$elementCache. Or an array If an array, the following keys can be used:
config
- Used to store the cached element in a custom cache configuration.key
- Used to define the key used in the Cache::write(). It will be prefixed with element_
callbacks
- Set to true to fire beforeRender and afterRender helper callbacks for this element. Defaults to false.
ignoreMissing
- Used to allow missing elements. Set to true to not throw exceptions.
plugin
- setting to false will force to use the application's element from plugin templates, when the plugin has element with same name. Defaults to true
string
Rendered Element
Cake\View\Exception\MissingElementException
elementExists(string $name)
Checks if an element exists
string
$name Name of template file in the templates/element/
folder, or MyPlugin.template
to check the template element from MyPlugin. If the element is not found in the plugin, the normal view path cascade will be searched.
bool
Success
enableAutoLayout(bool $enable)
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.
bool
$enable optional Boolean to turn on/off.
$this
end()
End a capturing block. The compliment to View::start()
$this
exists(string $name)
Check if a block exists
string
$name Name of the block
bool
extend(string $name)
Provides template or element extension/inheritance. Templates can extends a parent template and populate blocks in the parent template.
string
$name The template or element to 'extend' the current one with.
$this
LogicException
LogicException
fetch(string $name, string $default)
Fetch the content for a block. If a block is empty or undefined '' will be returned.
string
$name Name of the block
string
$default optional Default text
string
The block content or $default if the block does not exist.
get(string $var, mixed $default)
Returns the contents of the given View variable.
string
$var The view var you want the contents of.
mixed
$default optional The default/fallback content of $var.
mixed
The content of the named var if its set, otherwise $default.
getConfig(?string $key, mixed $default)
Get config value.
Currently if config is not set it fallbacks to checking corresponding view var with underscore prefix. Using underscore prefixed special view vars is deprecated and this fallback will be removed in CakePHP 4.1.0.
string|null
$key optional The key to get or null for the whole config.
mixed
$default optional The return value when the key does not exist.
mixed
Config value being read.
getConfigOrFail(string $key)
Returns the config for this specific key.
The config value for this key must exist, it can never be null.
string
$key The key to get.
mixed
Configuration data at the named key
InvalidArgumentException
getCurrentType()
Retrieve the current template type
string
getElementPaths(?string $plugin)
Get an iterator for element paths.
string|null
$plugin The plugin to fetch paths for.
\Generator
getEventManager()
Returns the Cake\Event\EventManager manager instance for this object.
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
\Cake\Event\EventManagerInterface
getLayout()
Get the name of the layout file to render the template inside of.
The name specified is the filename of the layout in templates/layout/
without the .php extension.
string
getLayoutPath()
Get path for layout files.
string
getLayoutPaths(?string $plugin)
Get an iterator for layout paths.
string|null
$plugin The plugin to fetch paths for.
\Generator
getName()
Returns the View's controller name.
string
getPlugin()
Returns the plugin name.
string|null
getRequest()
Gets the request instance.
\Cake\Http\ServerRequest
getResponse()
Gets the response instance.
\Cake\Http\Response
getSubDir()
Get sub-directory for this template files.
string
getTemplate()
Get the name of the template file to render. The name specified is the filename in templates/<SubFolder>/
without the .php extension.
string
getTemplatePath()
Get path for templates files.
string
getTheme()
Get the current view theme.
string|null
getVars()
Returns a list of variables available in the current View context
string[]
Array of the set view variable names.
helpers()
Get the helper registry in use by this View class.
\Cake\View\HelperRegistry
initialize()
Initialization hook method.
Properties like $helpers etc. cannot be initialized statically in your custom view class as they are overwritten by values from controller in constructor. So this method allows you to manipulate them as required after view instance is constructed.
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.
bool
loadHelper(string $name, array $config)
Loads a helper. Delegates to the HelperRegistry::load()
to load the helper
string
$name Name of the helper to load.
array
$config optional Settings for the helper
\Cake\View\Helper
a constructed helper object.
loadHelpers()
Interact with the HelperRegistry to load all the helpers.
$this
log(string $message, mixed $level, mixed $context)
Convenience method to write a message to Log. See Log::write() for more information on writing to logs.
string
$message Log message.
int|string
$level optional Error level.
string|array
$context optional Additional log data relevant to this message.
bool
Success of log write.
pluginSplit(string $name, bool $fallback)
Splits a dot syntax plugin name into its plugin and filename.
If $name does not have a dot, then index 0 will be null. It checks if the plugin is loaded, else filename will stay unchanged for filenames containing dot
string
$name The name you want to plugin split.
bool
$fallback optional If true uses the plugin set in the current Request when parsed plugin is not loaded
array
Array with 2 indexes. 0 => plugin name, 1 => filename.
prepend(string $name, mixed $value)
Prepend to an existing or new block.
Prepending to a new block will create the block.
string
$name Name of the block
mixed
$value The content for the block. Value will be type cast to string.
$this
render(?string $template, mixed $layout)
Renders view for given template file and layout.
Render triggers helper callbacks, which are fired before and after the template are rendered, as well as before and after the layout. The helper callbacks are called:
beforeRender
afterRender
beforeLayout
afterLayout
If View::$autoLayout is set to false
, the template will be returned bare.
Template and layout names can point to plugin templates or layouts. Using the Plugin.template
syntax a plugin template/layout/ can be used instead of the app ones. If the chosen plugin is not found the template will be located along the regular view path cascade.
string|null
$template optional Name of template file to use
string|false|null
$layout optional Layout to use. False to disable.
string
Rendered content.
Cake\Core\Exception\Exception
renderLayout(string $content, ?string $layout)
Renders a layout. Returns output from _render().
Several variables are created for use in layout.
string
$content Content to render in a template, wrapped by the surrounding layout.
string|null
$layout optional Layout name
string
Rendered output.
Cake\Core\Exception\Exception
reset(string $name)
Reset the content for a block. This will overwrite any existing content.
string
$name Name of the block
$this
set(mixed $name, mixed $value)
Saves a variable or an associative array of variables for use inside a template.
string|array
$name A string or an array of data.
mixed
$value optional Value in case $name is a string (which then works as the key). Unused if $name is an associative array, otherwise serves as the values to $name's keys.
$this
RuntimeException
setConfig(mixed $key, mixed $value, mixed $merge)
Sets the config.
Setting a specific value:
$this->setConfig('key', $value);
Setting a nested value:
$this->setConfig('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->setConfig(['one' => 'value', 'another' => 'value']);
string|array
$key The key to set, or a complete array of configs.
mixed|null
$value optional The value to set.
bool
$merge optional Whether to recursively merge or overwrite existing config, defaults to true.
$this
Cake\Core\Exception\Exception
setElementCache(string $elementCache)
Set The cache configuration View will use to store cached elements
string
$elementCache Cache config name.
$this
setEventManager(\Cake\Event\EventManagerInterface $eventManager)
Returns the Cake\Event\EventManagerInterface instance for this object.
You can use this instance to register any new listeners or callbacks to the object events, or create your own events and trigger them at will.
\Cake\Event\EventManagerInterface
$eventManager the eventManager to set
$this
setLayout(string $name)
Set the name of the layout file to render the template inside of.
The name specified is the filename of the layout in templates/layout/
without the .php extension.
string
$name Layout file name to set.
$this
setLayoutPath(string $path)
Set path for layout files.
string
$path Path for layout files.
$this
setPlugin(?string $name)
Sets the plugin name.
string|null
$name Plugin name.
$this
setRequest(\Cake\Http\ServerRequest $request)
Sets the request objects and configures a number of controller properties based on the contents of the request. The properties that get set are:
\Cake\Http\ServerRequest
$request Request instance.
$this
setResponse(\Cake\Http\Response $response)
Sets the response instance.
\Cake\Http\Response
$response Response instance.
$this
setSubDir(string $subDir)
Set sub-directory for this template files.
string
$subDir Sub-directory name.
$this
setTemplate(string $name)
Set the name of the template file to render. The name specified is the filename in templates/<SubFolder>/
without the .php extension.
string
$name Template file name to set.
$this
setTemplatePath(string $path)
Set path for templates files.
string
$path Path for template files.
$this
setTheme(?string $theme)
Set the view theme to use.
string|null
$theme Theme name.
$this
start(string $name)
Start capturing output for a 'block'
You can use start on a block multiple times to append or prepend content in a capture mode.
// Append content to an existing block. $this->start('content'); echo $this->fetch('content'); echo 'Some new content'; $this->end(); // Prepend content to an existing block $this->start('content'); echo 'Some new content'; echo $this->fetch('content'); $this->end();
string
$name The name of the block to capture for.
$this
ViewBlock instance.
\Cake\View\ViewBlock
\Cake\View\Helper\BreadcrumbsHelper
\Cake\View\Helper\FlashHelper
\Cake\View\Helper\FormHelper
\Cake\View\Helper\HtmlHelper
\Cake\View\Helper\NumberHelper
\Cake\View\Helper\PaginatorHelper
\Cake\View\Helper\TextHelper
\Cake\View\Helper\TimeHelper
\Cake\View\Helper\UrlHelper
Runtime config
array
Whether the config property has already been configured with defaults
bool
The currently rendering view file. Used for resolving parent files.
string
Currently rendering an element. Used for finding parent fragments for elements.
string
Default custom config options.
string[]
Default class name for new event objects.
string
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
\Cake\Event\EventManagerInterface
File extension. Defaults to ".php".
string
Helpers collection
\Cake\View\HelperRegistry
The names of views and their parents used with View::extend();
string[]
List of variables to collect from the associated controller.
string[]
Holds an array of paths.
string[]
Holds an array of plugin paths.
string[][]
Content stack, used for nested templates that all use View::extend();
string[]
ViewBlock class.
string
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 templates.
bool
The Cache configuration View will use to store cached elements. Changing this will change the default configuration elements are stored under. You can also choose a cache config per element.
string
An array of names of built-in helpers to include.
array
The name of the layout file to render the template inside of. The name specified is the filename of the layout in templates/layout/
without the .php extension.
string
The name of the layouts subfolder containing layouts for this View.
string
Name of the controller that created the View if any.
string
The name of the plugin.
string|null
An instance of a \Cake\Http\ServerRequest object that contains information about the current request.
This object contains all the information about a request and several methods for reading additional information about the request.
\Cake\Http\ServerRequest
Reference to the Response object
\Cake\Http\Response
Sub-directory for this template file. This is often used for extension based routing.
Eg. With an xml
extension, $subDir would be xml/
string
The name of the template file to render. The name specified is the filename in templates/<SubFolder>/
without the .php extension.
string
The name of the subfolder containing templates for this View.
string
The view theme to use.
string|null
An array of variables
array
© 2005–present 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/4.1/class-Cake.View.AjaxView.html