TYPE_VIEW
TYPE_VIEW = 'view' : string
Constant for view file type 'view'
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.
None found |
None found |
None found |
None found |
None found |
$passedArgs : array
Current passed params. Passed to View from the creating Controller for convenience.
None found |
None found |
None found |
None found |
None found |
$Breadcrumbs : \Cake\View\Helper\BreadcrumbsHelper
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
$_helpers : \Cake\View\HelperRegistry
Helpers collection
None found |
$Blocks : \Cake\View\ViewBlock
ViewBlock instance.
None found |
None found |
None found |
None found |
$templatePath : string
The name of the subfolder containing templates for this View.
None found |
$template : string
The name of the template file to render. The name specified is the filename in /src/Template/<SubFolder> without the .ctp extension.
None found |
$layout : string
The name of the layout file to render the template inside of. The name specified is the filename of the layout in /src/Template/Layout without the .ctp extension.
None found |
$layoutPath : string
The name of the layouts subfolder containing layouts for this View.
None found |
$autoLayout : boolean
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.
None found |
None found |
$subDir : string
Sub-directory for this template file. This is often used for extension based routing.
Eg. With an xml
extension, $subDir would be xml/
None found |
None found |
$request : \Cake\Http\ServerRequest
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.
None found |
$response : \Cake\Http\Response
Reference to the Response object
None found |
$elementCache : 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.
None found |
$_passedVars : array
List of variables to collect from the associated controller.
None found |
None found |
None found |
$_parents : array
The names of views and their parents used with View::extend();
None found |
$_current : string
The currently rendering view file. Used for resolving parent files.
None found |
$_currentType : string
Currently rendering an element. Used for finding parent fragments for elements.
None found |
$_stack : array
Content stack, used for nested templates that all use View::extend();
None found |
None found |
$_eventManager : \Cake\Event\EventManagerInterface|\Cake\Event\EventManager
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
None found |
None found |
$_viewBuilder : \Cake\View\ViewBuilder
The view builder instance being used.
None found |
__construct(\Cake\Http\ServerRequest|null $request = null, \Cake\Http\Response|null $response = null, \Cake\Event\EventManager|null $eventManager = null, array $viewOptions = array())
Constructor
\Cake\Http\ServerRequest|null | $request | The request object. |
\Cake\Http\Response|null | $response | The response object. |
\Cake\Event\EventManager|null | $eventManager | Event manager object. |
array | $viewOptions | View options. |
None found |
initialize() : void
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.
None found |
getRequest() : \Cake\Http\ServerRequest
Gets the request instance.
since | 3.7.0 |
---|
setRequest(\Cake\Http\ServerRequest $request) : $this
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. |
since | 3.7.0 |
---|
getResponse() : \Cake\Http\Response
Gets the response instance.
since | 3.7.0 |
---|
setResponse(\Cake\Http\Response $response) : $this
Sets the response instance.
\Cake\Http\Response | $response | Response instance. |
since | 3.7.0 |
---|
None found |
setTemplatePath(string $path) : $this
Set path for templates files.
string | $path | Path for template files. |
None found |
templatePath(string|null $path = null) : string|null
Get/set path for templates files.
string|null | $path | Path for template files. If null returns current path. |
None found |
None found |
setLayoutPath(string $path) : $this
Set path for layout files.
string | $path | Path for layout files. |
None found |
layoutPath(string|null $path = null) : string|null
Get/set path for layout files.
string|null | $path | Path for layout files. If null returns current path. |
None found |
isAutoLayoutEnabled() : boolean
Returns if CakePHP's conventional mode of applying layout files is enabled.
Disabled means that layouts will not be automatically applied to rendered views.
None found |
enableAutoLayout(boolean $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.
boolean | $enable | Boolean to turn on/off. |
None found |
disableAutoLayout() : $this
Turns off CakePHP's conventional mode of applying layout files.
Layouts will not be automatically applied to rendered views.
None found |
autoLayout(boolean|null $autoLayout = null) : boolean|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 templates.
boolean|null | $autoLayout | Boolean to turn on/off. If null returns current value. |
None found |
None found |
setTheme(string|null $theme) : $this
Set the view theme to use.
string|null | $theme | Theme name. |
None found |
theme(string|null $theme = null) : string|null
The view theme to use.
string|null | $theme | Theme name. If null returns current theme. |
None found |
getTemplate() : string
Get the name of the template file to render. The name specified is the filename in /src/Template/<SubFolder> without the .ctp extension.
None found |
setTemplate(string $name) : $this
Set the name of the template file to render. The name specified is the filename in /src/Template/<SubFolder> without the .ctp extension.
string | $name | Template file name to set. |
None found |
template(string|null $name = null) : string|null
Get/set the name of the template file to render. The name specified is the filename in /src/Template/<SubFolder> without the .ctp extension.
string|null | $name | Template file name to set. If null returns current name. |
None found |
getLayout() : string
Get the name of the layout file to render the template inside of.
The name specified is the filename of the layout in /src/Template/Layout without the .ctp extension.
None found |
setLayout(string $name) : $this
Set the name of the layout file to render the template inside of.
The name specified is the filename of the layout in /src/Template/Layout without the .ctp extension.
string | $name | Layout file name to set. |
None found |
layout(string|null $name = null) : string|null
Get/set the name of the layout file to render the template inside of.
The name specified is the filename of the layout in /src/Template/Layout without the .ctp extension.
string|null | $name | Layout file name to set. If null returns current name. |
None found |
element(string $name, array $data = array(), array $options = array()) : string
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 /src/Template/Element/ folder,
or |
array | $data | Array of data to be made available to the rendered view (i.e. the Element) |
array | $options | Array of options. Possible keys are:
|
When an element is missing and ignoreMissing
is false.
Rendered Element
None found |
cache(callable $block, array $options = array()) : string
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 | The options defining the cache key etc. |
When $options is lacking a 'key' option.
The rendered content.
None found |
elementExists(string $name) : boolean
Checks if an element exists
string | $name | Name of template file in the /src/Template/Element/ folder,
or |
Success
None found |
render(string|false|null $view = null, string|null $layout = null) : string|null
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::$autoRender is false and no $layout
is provided, the template will be returned bare.
Template and layout names can point to plugin templates/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|false|null | $view | Name of view file to use |
string|null | $layout | Layout to use. |
If there is an error in the view.
Rendered content or null if content already rendered and returned earlier.
triggers |
View.beforeRender $this, [$viewFileName] View.afterRender $this, [$viewFileName] |
---|
renderLayout(string $content, string|null $layout = null) : mixed
Renders a layout. Returns output from _render(). Returns false on error.
Several variables are created for use in layout.
string | $content | Content to render in a template, wrapped by the surrounding layout. |
string|null | $layout | Layout name |
if there is an error in the view.
Rendered output, or false on error
triggers |
View.beforeLayout $this, [$layoutFileName] View.afterLayout $this, [$layoutFileName] |
---|
getVars() : array<mixed,string>
Returns a list of variables available in the current View context
Array of the set view variable names.
None found |
get(string $var, mixed $default = null) : mixed
Returns the contents of the given View variable.
string | $var | The view var you want the contents of. |
mixed | $default | The default/fallback content of $var. |
The content of the named var if its set, otherwise $default.
None found |
blocks() : array
Get the names of all the existing blocks.
An array containing the blocks.
None found |
start(string $name) : $this
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. |
None found |
append(string $name, mixed $value = null) : $this
Append to an existing or new block.
Appending 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. |
None found |
prepend(string $name, mixed $value) : $this
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. |
None found |
assign(string $name, mixed $value) : $this
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. |
None found |
reset(string $name) : $this
Reset the content for a block. This will overwrite any existing content.
string | $name | Name of the block |
None found |
fetch(string $name, string $default = '') : string
Fetch the content for a block. If a block is empty or undefined '' will be returned.
string | $name | Name of the block |
string | $default | Default text |
The block content or $default if the block does not exist.
None found |
None found |
exists(string $name) : boolean
Check if a block exists
string | $name | Name of the block |
None found |
extend(string $name) : $this
Provides template or element extension/inheritance. Views can extends a parent view and populate blocks in the parent template.
string | $name | The template or element to 'extend' the current one with. |
when you extend a template with itself or make extend loops.
when you extend an element which doesn't exist
None found |
uuid(string $object, string $url) : string
Generates a unique, non-random DOM ID for an object, based on the object type and the target URL.
string | $object | Type of object, i.e. 'form' or 'link' |
string | $url | The object's target URL |
None found |
None found |
__get(string $name) : mixed
Magic accessor for helpers.
string | $name | Name of the attribute to get. |
None found |
__set(string $name, mixed $value) : void
Magic setter for deprecated properties.
string | $name | Name to property. |
mixed | $value | Value for property. |
None found |
loadHelpers() : $this
Interact with the HelperRegistry to load all the helpers.
None found |
helpers() : \Cake\View\HelperRegistry
Get the helper registry in use by this View class.
None found |
loadHelper(string $name, array $config = array()) : \Cake\View\Helper
Loads a helper. Delegates to the `HelperRegistry::load()` to load the helper
string | $name | Name of the helper to load. |
array | $config | Settings for the helper |
a constructed helper object.
None found |
setSubDir(string $subDir) : $this
Set sub-directory for this template files.
string | $subDir | Sub-directory name. |
since | 3.7.0 |
---|
since | 3.7.0 |
---|
since | 3.7.0 |
---|
setPlugin(string $name) : $this
Sets the plugin name.
string | $name | Plugin name. |
since | 3.7.0 |
---|
setElementCache(string $elementCache) : $this
Set The cache configuration View will use to store cached elements
string | $elementCache | Cache config name. |
since | 3.7.0 |
---|
pluginSplit(string $name, boolean $fallback = true) : array
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. |
boolean | $fallback | If true uses the plugin set in the current Request when parsed plugin is not loaded |
Array with 2 indexes. 0 => plugin name, 1 => filename
None found |
eventManager(\Cake\Event\EventManager|null $eventManager = null) : \Cake\Event\EventManager
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\EventManager|null | $eventManager | the eventManager to set |
None found |
getEventManager() : \Cake\Event\EventManager
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.
None found |
setEventManager(\Cake\Event\EventManager $eventManager) : $this
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\EventManager | $eventManager | the eventManager to set |
None found |
dispatchEvent(string $name, array|null $data = null, object|null $subject = null) : \Cake\Event\Event
Wrapper for creating and dispatching events.
Returns a dispatched event.
string | $name | Name of the event. |
array|null | $data | Any value you wish to be transported with this event to it can be read by listeners. |
object|null | $subject | The object that this event applies to ($this by default). |
None found |
log(mixed $msg, integer|string $level = \Psr\Log\LogLevel::ERROR, string|array $context = array()) : boolean
Convenience method to write a message to Log. See Log::write() for more information on writing to logs.
mixed | $msg | Log message. |
integer|string | $level | Error level. |
string|array | $context | Additional log data relevant to this message. |
Success of log write.
None found |
requestAction(string|array $url, array $extra = array()) : mixed
Calls a controller's method from any location. Can be used to connect controllers together or tie plugins into a main application. requestAction can be used to return rendered views or fetch the return value from controller actions.
Under the hood this method uses Router::reverse() to convert the $url parameter into a string URL. You should use URL formats that are compatible with Router::reverse()
A basic example getting the return value of the controller action:
$variables = $this->requestAction('/articles/popular');
A basic example of request action to fetch a rendered page without the layout.
$viewHtml = $this->requestAction('/articles/popular', ['return']);
You can also pass the URL as an array:
$vars = $this->requestAction(['controller' => 'articles', 'action' => 'popular']);
You can pass POST, GET, COOKIE and other data into the request using the appropriate keys.
Cookies can be passed using the cookies
key. Get parameters can be set with query
and post
data can be sent using the post
key.
$vars = $this->requestAction('/articles/popular', [
'query' => ['page' => 1],
'cookies' => ['remember_me' => 1],
]);
By default actions dispatched with this method will use the global $_SERVER and $_ENV values. If you want to override those values for a request action, you can specify the values:
$vars = $this->requestAction('/articles/popular', [
'environment' => ['CONTENT_TYPE' => 'application/json']
]);
By default actions dispatched with this method will use the standard session object. If you want a particular session instance to be used, you need to specify it.
$vars = $this->requestAction('/articles/popular', [
'session' => new Session($someSessionConfig)
]);
string|array | $url | String or array-based url. Unlike other url arrays in CakePHP, this url will not automatically handle passed arguments in the $url parameter. |
array | $extra | if array includes the key "return" it sets the autoRender to true. Can also be used to submit GET/POST data, and passed arguments. |
Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
None found |
viewBuilder() : \Cake\View\ViewBuilder
Get the view builder being used.
None found |
createView(string|null $viewClass = null) : \Cake\View\View
Constructs the view class instance based on the current configuration.
string|null | $viewClass | Optional namespaced class name of the View class to instantiate. |
If view class was not found.
None found |
set(string|array $name, mixed $value = null) : $this
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 | 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. |
None found |
viewOptions(string|array|null $options = null, boolean $merge = true) : array
Get/Set valid view options in the object's _validViewOptions property. The property is created as an empty array if it is not set. If called without any parameters it will return the current list of valid view options. See `createView()`.
string|array|null | $options | string or array of string to be appended to _validViewOptions. |
boolean | $merge | Whether to merge with or override existing valid View options.
Defaults to |
The updated view options as an array.
None found |
_render(string $viewFile, array $data = array()) : string
Renders and returns output for given template filename with its array of data. Handles parent/extended templates.
string | $viewFile | Filename of the view |
array | $data | Data to include in rendered view. If empty the current View::$viewVars will be used. |
When a block is left open.
Rendered output
triggers |
View.beforeRenderFile $this, [$viewFile] View.afterRenderFile $this, [$viewFile, $content] |
---|
_evaluate(string $viewFile, array $dataForView) : string
Sandbox method to evaluate a template / view script in.
string | $viewFile | Filename of the view |
array | $dataForView | Data to include in rendered view. |
Rendered output
None found |
_getViewFileName(string|null $name = null) : string
Returns filename of given action's template file (.ctp) 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.ctp views. You can change the inflection rule by overriding _inflectViewFileName.
string|null | $name | Controller action to find template filename for |
when a view file could not be found.
Template filename
None found |
_inflectViewFileName(string $name) : string
Change the name of a view template file into underscored format.
string | $name | Name of file which should be inflected. |
File name after conversion
None found |
_checkFilePath(string $file, string $path) : string
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. |
The file path
None found |
_getLayoutFileName(string|null $name = null) : string
Returns layout filename for this template as a string.
string|null | $name | The name of the layout to find. |
when a layout cannot be located
Filename for layout file (.ctp).
None found |
_getElementFileName(string $name, boolean $pluginCheck = true) : string|false
Finds an element filename, returns false on failure.
string | $name | The name of the element to find. |
boolean | $pluginCheck |
|
Either a string to the element filename or false when one can't be found.
None found |
_getSubPaths(string $basePath) : array
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. |
Array with all the templates paths.
None found |
_paths(string|null $plugin = null, boolean $cached = true) : array
Return all possible paths to find view files in order
string|null | $plugin | Optional plugin name to scan for view files. |
boolean | $cached | Set to false to force a refresh of view paths. Default true. |
paths
None found |
_elementCache(string $name, array $data, array $options) : array
Generate the cache configuration options for an element.
string | $name | Element name |
array | $data | Data |
array | $options | Element options |
Element Cache configuration.
None found |
_renderElement(string $file, array $data, array $options) : string
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 |
triggers |
View.beforeRender $this, [$file] View.afterRender $this, [$file, $element] |
---|
cell(string $cell, array $data = array(), array $options = array()) : \Cake\View\Cell
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.: |
array | $data | Additional arguments for cell method. e.g.:
|
array | $options | Options for Cell's constructor |
If Cell class was not found.
If Cell class does not specified cell action.
The cell instance
None found |
_createCell(string $className, string $action, string $plugin, array $options) : \Cake\View\Cell
Create and configure the cell instance.
string | $className | The cell classname. |
string | $action | The action name. |
string | $plugin | The plugin name. |
array | $options | The constructor options for the cell. |
None found |