\Cake\ViewAjaxView

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.

Summary

Methods
Properties
Constants
__construct()
initialize()
getRequest()
setRequest()
getResponse()
setResponse()
getTemplatePath()
setTemplatePath()
templatePath()
getLayoutPath()
setLayoutPath()
layoutPath()
isAutoLayoutEnabled()
enableAutoLayout()
disableAutoLayout()
autoLayout()
getTheme()
setTheme()
theme()
getTemplate()
setTemplate()
template()
getLayout()
setLayout()
layout()
element()
cache()
elementExists()
render()
renderLayout()
getVars()
get()
blocks()
start()
append()
prepend()
assign()
reset()
fetch()
end()
exists()
extend()
uuid()
getCurrentType()
__get()
__set()
loadHelpers()
helpers()
loadHelper()
setSubDir()
getSubDir()
getPlugin()
setPlugin()
setElementCache()
pluginSplit()
eventManager()
getEventManager()
setEventManager()
dispatchEvent()
log()
requestAction()
viewBuilder()
createView()
set()
viewOptions()
$passedArgs
$hasRendered
$uuids
$viewClass
$viewVars
$Breadcrumbs
$Flash
$Form
$Html
$Number
$Paginator
$Rss
$Session
$Text
$Time
$Url
$Blocks
$view
$viewPath
TYPE_VIEW
TYPE_TEMPLATE
TYPE_ELEMENT
NAME_ELEMENT
TYPE_LAYOUT
NAME_TEMPLATE
_render()
_evaluate()
_getViewFileName()
_inflectViewFileName()
_checkFilePath()
_getLayoutFileName()
_getElementFileName()
_getSubPaths()
_paths()
_elementCache()
_renderElement()
cell()
_createCell()
$_helpers
$Blocks
$plugin
$name
$helpers
$templatePath
$template
$layout
$layoutPath
$autoLayout
$_ext
$subDir
$theme
$request
$response
$elementCache
$_passedVars
$_paths
$_pathsForPlugin
$_parents
$_current
$_currentType
$_stack
$_viewBlockClass
$_eventManager
$_eventClass
$_viewBuilder
N/A
No private methods found
No private properties found
N/A

Constants

TYPE_VIEW

TYPE_VIEW = 'view' : string

Constant for view file type 'view'

TYPE_TEMPLATE

TYPE_TEMPLATE = 'view' : string

Constant for view file type 'template'.

TYPE_ELEMENT

TYPE_ELEMENT = 'element' : string

Constant for view file type 'element'

NAME_ELEMENT

NAME_ELEMENT = 'Element' : string

Constant for name of view file 'Element'

TYPE_LAYOUT

TYPE_LAYOUT = 'layout' : string

Constant for view file type 'layout'

NAME_TEMPLATE

NAME_TEMPLATE = 'Template' : string

Constant for template folder 'Template'

Properties

$passedArgs

$passedArgs : array

Current passed params. Passed to View from the creating Controller for convenience.

Type

array

$hasRendered

$hasRendered : boolean

True when the view has been rendered.

Type

boolean

$uuids

$uuids : array

List of generated DOM UUIDs.

Type

array

$viewClass

$viewClass : string|null

The name of default View class.

Type

string|null

$viewVars

$viewVars : array

Variables for the view

Type

array

$Breadcrumbs

$Breadcrumbs : \Cake\View\Helper\BreadcrumbsHelper

Type

\Cake\View\Helper\BreadcrumbsHelper

$Flash

$Flash : \Cake\View\Helper\FlashHelper

Type

\Cake\View\Helper\FlashHelper

$Form

$Form : \Cake\View\Helper\FormHelper

Type

\Cake\View\Helper\FormHelper

$Html

$Html : \Cake\View\Helper\HtmlHelper

Type

\Cake\View\Helper\HtmlHelper

$Number

$Number : \Cake\View\Helper\NumberHelper

Type

\Cake\View\Helper\NumberHelper

$Paginator

$Paginator : \Cake\View\Helper\PaginatorHelper

Type

\Cake\View\Helper\PaginatorHelper

$Rss

$Rss : \Cake\View\Helper\RssHelper

Type

\Cake\View\Helper\RssHelper

$Session

$Session : \Cake\View\Helper\SessionHelper

Type

\Cake\View\Helper\SessionHelper

$Text

$Text : \Cake\View\Helper\TextHelper

Type

\Cake\View\Helper\TextHelper

$Time

$Time : \Cake\View\Helper\TimeHelper

Type

\Cake\View\Helper\TimeHelper

$Url

$Url : \Cake\View\Helper\UrlHelper

Type

\Cake\View\Helper\UrlHelper

$Blocks

$Blocks : \Cake\View\ViewBlock

Type

\Cake\View\ViewBlock

$view

$view : string

Type

string

$viewPath

$viewPath : string

Type

string

$plugin

$plugin : string|null

The name of the plugin.

Type

string|null

$name

$name : string

Name of the controller that created the View if any.

Type

string

$helpers

$helpers : array

An array of names of built-in helpers to include.

Type

array

$templatePath

$templatePath : string

The name of the subfolder containing templates for this View.

Type

string

$template

$template : string

The name of the template file to render. The name specified is the filename in /src/Template/<SubFolder> without the .ctp extension.

Type

string

$layout

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

Type

string

$layoutPath

$layoutPath : string

The name of the layouts subfolder containing layouts for this View.

Type

string

$autoLayout

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

Type

boolean

$_ext

$_ext : string

File extension. Defaults to CakePHP's template ".ctp".

Type

string

$subDir

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

Type

string

$theme

$theme : string|null

The view theme to use.

Type

string|null

$request

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

Type

\Cake\Http\ServerRequest

$response

$response : \Cake\Http\Response

Reference to the Response object

Type

\Cake\Http\Response

$elementCache

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

Type

string

$_passedVars

$_passedVars : array

List of variables to collect from the associated controller.

Type

array

$_paths

$_paths : array

Holds an array of paths.

Type

array

$_pathsForPlugin

$_pathsForPlugin : array

Holds an array of plugin paths.

Type

array

$_parents

$_parents : array

The names of views and their parents used with View::extend();

Type

array

$_current

$_current : string

The currently rendering view file. Used for resolving parent files.

Type

string

$_currentType

$_currentType : string

Currently rendering an element. Used for finding parent fragments for elements.

Type

string

$_stack

$_stack : array

Content stack, used for nested templates that all use View::extend();

Type

array

$_viewBlockClass

$_viewBlockClass : string

ViewBlock class.

Type

string

$_eventClass

$_eventClass : string

Default class name for new event objects.

Type

string

$_viewBuilder

$_viewBuilder : \Cake\View\ViewBuilder

The view builder instance being used.

Type

\Cake\View\ViewBuilder

Methods

__construct()

__construct(\Cake\Http\ServerRequest|null  $request = null, \Cake\Http\Response|null  $response = null, \Cake\Event\EventManager|null  $eventManager = null, array  $viewOptions = array()) 

Constructor

Parameters

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

initialize()

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.

setRequest()

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:

  • $this->request - To the $request parameter
  • $this->plugin - To the value returned by $request->getParam('plugin')
  • $this->passedArgs - Same as $request->params['pass]

Parameters

\Cake\Http\ServerRequest $request

Request instance.

Returns

$this

getResponse()

getResponse() : \Cake\Http\Response

Gets the response instance.

Returns

\Cake\Http\Response

setResponse()

setResponse(\Cake\Http\Response  $response) : $this

Sets the response instance.

Parameters

\Cake\Http\Response $response

Response instance.

Returns

$this

getTemplatePath()

getTemplatePath() : string

Get path for templates files.

Returns

string

setTemplatePath()

setTemplatePath(string  $path) : $this

Set path for templates files.

Parameters

string $path

Path for template files.

Returns

$this

templatePath()

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

Get/set path for templates files.

Parameters

string|null $path

Path for template files. If null returns current path.

Returns

string|null

getLayoutPath()

getLayoutPath() : string

Get path for layout files.

Returns

string

setLayoutPath()

setLayoutPath(string  $path) : $this

Set path for layout files.

Parameters

string $path

Path for layout files.

Returns

$this

layoutPath()

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

Get/set path for layout files.

Parameters

string|null $path

Path for layout files. If null returns current path.

Returns

string|null

isAutoLayoutEnabled()

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.

Returns

boolean

enableAutoLayout()

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.

Parameters

boolean $enable

Boolean to turn on/off.

Returns

$this

disableAutoLayout()

disableAutoLayout() : $this

Turns off CakePHP's conventional mode of applying layout files.

Layouts will not be automatically applied to rendered views.

Returns

$this

autoLayout()

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.

Parameters

boolean|null $autoLayout

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

Returns

boolean|null

getTheme()

getTheme() : string|null

Get the current view theme.

Returns

string|null

setTheme()

setTheme(string|null  $theme) : $this

Set the view theme to use.

Parameters

string|null $theme

Theme name.

Returns

$this

theme()

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

The view theme to use.

Parameters

string|null $theme

Theme name. If null returns current theme.

Returns

string|null

getTemplate()

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.

Returns

string

setTemplate()

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.

Parameters

string $name

Template file name to set.

Returns

$this

template()

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.

Parameters

string|null $name

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

Returns

string|null

getLayout()

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.

Returns

string

setLayout()

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.

Parameters

string $name

Layout file name to set.

Returns

$this

layout()

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.

Parameters

string|null $name

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

Returns

string|null

element()

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.

Parameters

string $name

Name of template file in the /src/Template/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

Array of data to be made available to the rendered view (i.e. the Element)

array $options

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

Throws

\Cake\View\Exception\MissingElementException

When an element is missing and ignoreMissing is false.

Returns

string —

Rendered Element

cache()

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.

Parameters

callable $block

The block of code that you want to cache the output of.

array $options

The options defining the cache key etc.

Throws

\RuntimeException

When $options is lacking a 'key' option.

Returns

string —

The rendered content.

elementExists()

elementExists(string  $name) : boolean

Checks if an element exists

Parameters

string $name

Name of template file in the /src/Template/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.

Returns

boolean —

Success

render()

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.

Parameters

string|false|null $view

Name of view file to use

string|null $layout

Layout to use.

Throws

\Cake\Core\Exception\Exception

If there is an error in the view.

Returns

string|null —

Rendered content or null if content already rendered and returned earlier.

renderLayout()

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.

Parameters

string $content

Content to render in a template, wrapped by the surrounding layout.

string|null $layout

Layout name

Throws

\Cake\Core\Exception\Exception

if there is an error in the view.

Returns

mixed —

Rendered output, or false on error

getVars()

getVars() : array<mixed,string>

Returns a list of variables available in the current View context

Returns

array<mixed,string> —

Array of the set view variable names.

get()

get(string  $var, mixed  $default = null) : mixed

Returns the contents of the given View variable.

Parameters

string $var

The view var you want the contents of.

mixed $default

The default/fallback content of $var.

Returns

mixed —

The content of the named var if its set, otherwise $default.

blocks()

blocks() : array

Get the names of all the existing blocks.

Returns

array —

An array containing the blocks.

start()

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

Parameters

string $name

The name of the block to capture for.

Returns

$this

append()

append(string  $name, mixed  $value = null) : $this

Append to an existing or new block.

Appending to a new block will create the block.

Parameters

string $name

Name of the block

mixed $value

The content for the block. Value will be type cast to string.

Returns

$this

prepend()

prepend(string  $name, mixed  $value) : $this

Prepend to an existing or new block.

Prepending to a new block will create the block.

Parameters

string $name

Name of the block

mixed $value

The content for the block. Value will be type cast to string.

Returns

$this

assign()

assign(string  $name, mixed  $value) : $this

Set the content for a block. This will overwrite any existing content.

Parameters

string $name

Name of the block

mixed $value

The content for the block. Value will be type cast to string.

Returns

$this

reset()

reset(string  $name) : $this

Reset the content for a block. This will overwrite any existing content.

Parameters

string $name

Name of the block

Returns

$this

fetch()

fetch(string  $name, string  $default = '') : string

Fetch the content for a block. If a block is empty or undefined '' will be returned.

Parameters

string $name

Name of the block

string $default

Default text

Returns

string —

The block content or $default if the block does not exist.

end()

end() : $this

End a capturing block. The compliment to View::start()

Returns

$this

exists()

exists(string  $name) : boolean

Check if a block exists

Parameters

string $name

Name of the block

Returns

boolean

extend()

extend(string  $name) : $this

Provides template or element extension/inheritance. Views can extends a parent view and populate blocks in the parent template.

Parameters

string $name

The template or element to 'extend' the current one with.

Throws

\LogicException

when you extend a template with itself or make extend loops.

\LogicException

when you extend an element which doesn't exist

Returns

$this

uuid()

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.

Parameters

string $object

Type of object, i.e. 'form' or 'link'

string $url

The object's target URL

Returns

string

getCurrentType()

getCurrentType() : string

Retrieve the current view type

Returns

string

__get()

__get(string  $name) : mixed

Magic accessor for helpers.

Parameters

string $name

Name of the attribute to get.

Returns

mixed

__set()

__set(string  $name, mixed  $value) : void

Magic setter for deprecated properties.

Parameters

string $name

Name to property.

mixed $value

Value for property.

loadHelpers()

loadHelpers() : $this

Interact with the HelperRegistry to load all the helpers.

Returns

$this

helpers()

helpers() : \Cake\View\HelperRegistry

Get the helper registry in use by this View class.

Returns

\Cake\View\HelperRegistry

loadHelper()

loadHelper(string  $name, array  $config = array()) : \Cake\View\Helper

Loads a helper. Delegates to the `HelperRegistry::load()` to load the helper

Parameters

string $name

Name of the helper to load.

array $config

Settings for the helper

Returns

\Cake\View\Helper

a constructed helper object.

setSubDir()

setSubDir(string  $subDir) : $this

Set sub-directory for this template files.

Parameters

string $subDir

Sub-directory name.

Returns

$this

getSubDir()

getSubDir() : string

Get sub-directory for this template files.

Returns

string

getPlugin()

getPlugin() : string|null

Returns the plugin name.

Returns

string|null

setPlugin()

setPlugin(string  $name) : $this

Sets the plugin name.

Parameters

string $name

Plugin name.

Returns

$this

setElementCache()

setElementCache(string  $elementCache) : $this

Set The cache configuration View will use to store cached elements

Parameters

string $elementCache

Cache config name.

Returns

$this

pluginSplit()

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

Parameters

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

Returns

array —

Array with 2 indexes. 0 => plugin name, 1 => filename

eventManager()

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.

Parameters

\Cake\Event\EventManager|null $eventManager

the eventManager to set

Returns

\Cake\Event\EventManager

getEventManager()

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.

Returns

\Cake\Event\EventManager

setEventManager()

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.

Parameters

\Cake\Event\EventManager $eventManager

the eventManager to set

Returns

$this

dispatchEvent()

dispatchEvent(string  $name, array|null  $data = null, object|null  $subject = null) : \Cake\Event\Event

Wrapper for creating and dispatching events.

Returns a dispatched event.

Parameters

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

Returns

\Cake\Event\Event

log()

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.

Parameters

mixed $msg

Log message.

integer|string $level

Error level.

string|array $context

Additional log data relevant to this message.

Returns

boolean —

Success of log write.

requestAction()

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

Examples

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']);

Passing other request data

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],
]);

Sending environment or header values

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']
]);

Transmitting the session

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)
]);

Parameters

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.

Returns

mixed —

Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.

viewBuilder()

viewBuilder() : \Cake\View\ViewBuilder

Get the view builder being used.

Returns

\Cake\View\ViewBuilder

createView()

createView(string|null  $viewClass = null) : \Cake\View\View

Constructs the view class instance based on the current configuration.

Parameters

string|null $viewClass

Optional namespaced class name of the View class to instantiate.

Throws

\Cake\View\Exception\MissingViewException

If view class was not found.

Returns

\Cake\View\View

set()

set(string|array  $name, mixed  $value = null) : $this

Saves a variable or an associative array of variables for use inside a template.

Parameters

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.

Returns

$this

viewOptions()

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

Parameters

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

Returns

array —

The updated view options as an array.

_render()

_render(string  $viewFile, array  $data = array()) : string

Renders and returns output for given template filename with its array of data. Handles parent/extended templates.

Parameters

string $viewFile

Filename of the view

array $data

Data to include in rendered view. If empty the current View::$viewVars will be used.

Throws

\LogicException

When a block is left open.

Returns

string —

Rendered output

_evaluate()

_evaluate(string  $viewFile, array  $dataForView) : string

Sandbox method to evaluate a template / view script in.

Parameters

string $viewFile

Filename of the view

array $dataForView

Data to include in rendered view.

Returns

string —

Rendered output

_getViewFileName()

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

Parameters

string|null $name

Controller action to find template filename for

Throws

\Cake\View\Exception\MissingTemplateException

when a view file could not be found.

Returns

string —

Template filename

_inflectViewFileName()

_inflectViewFileName(string  $name) : string

Change the name of a view template file into underscored format.

Parameters

string $name

Name of file which should be inflected.

Returns

string —

File name after conversion

_checkFilePath()

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

Parameters

string $file

The path to the template file.

string $path

Base path that $file should be inside of.

Throws

\InvalidArgumentException

Returns

string —

The file path

_getLayoutFileName()

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

Returns layout filename for this template as a string.

Parameters

string|null $name

The name of the layout to find.

Throws

\Cake\View\Exception\MissingLayoutException

when a layout cannot be located

Returns

string —

Filename for layout file (.ctp).

_getElementFileName()

_getElementFileName(string  $name, boolean  $pluginCheck = true) : string|false

Finds an element filename, returns false on failure.

Parameters

string $name

The name of the element to find.

boolean $pluginCheck
  • if false will ignore the request's plugin if parsed plugin is not loaded

Returns

string|false —

Either a string to the element filename or false when one can't be found.

_getSubPaths()

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

Parameters

string $basePath

Base path on which to get the prefixed one.

Returns

array —

Array with all the templates paths.

_paths()

_paths(string|null  $plugin = null, boolean  $cached = true) : array

Return all possible paths to find view files in order

Parameters

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.

Returns

array —

paths

_elementCache()

_elementCache(string  $name, array  $data, array  $options) : array

Generate the cache configuration options for an element.

Parameters

string $name

Element name

array $data

Data

array $options

Element options

Returns

array —

Element Cache configuration.

_renderElement()

_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

Parameters

string $file

Element file path

array $data

Data to render

array $options

Element options

Returns

string

cell()

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.

Parameters

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

Additional arguments for cell method. e.g.: cell('TagCloud::smallList', ['a1' => 'v1', 'a2' => 'v2']) maps to View\Cell\TagCloud::smallList(v1, v2)

array $options

Options for Cell's constructor

Throws

\Cake\View\Exception\MissingCellException

If Cell class was not found.

\BadMethodCallException

If Cell class does not specified cell action.

Returns

\Cake\View\Cell

The cell instance

_createCell()

_createCell(string  $className, string  $action, string  $plugin, array  $options) : \Cake\View\Cell

Create and configure the cell instance.

Parameters

string $className

The cell classname.

string $action

The action name.

string $plugin

The plugin name.

array $options

The constructor options for the cell.

Returns

\Cake\View\Cell