Class XmlView
A view class that is used for creating XML responses.
By setting the '_serialize' key in your controller, you can specify a view variable that should be serialized to XML and used as the response for the request. This allows you to omit views + layouts, if your just need to emit a single view variable as the XML response.
In your controller, you could do the following:
$this->set(['posts' => $posts, '_serialize' => true]);When the view is rendered, the $posts view variable will be serialized
into XML.
Note The view variable you specify must be compatible with Xml::fromArray().
You can also define '_serialize' as an array. This will create an additional
top level element named <response> containing all the named view variables:
$this->set(compact('posts', 'users', 'stuff'));
$this->set('_serialize', true);The above would generate a XML object that looks like:
<response><posts>...</posts><users>...</users></response>
You can also set '_serialize' to a string or array to serialize only the
specified view variables.
If you don't use the _serialize key, you will need a view. You can use extended
views to provide layout like functionality.
Constants
- 
          
          stringNAME_ELEMENT ¶'Element'Constant for name of view file 'Element' 
- 
          
          stringNAME_TEMPLATE ¶'Template'Constant for template folder 'Template' 
- 
          
          stringTYPE_ELEMENT ¶'element'Constant for view file type 'element' 
- 
          
          stringTYPE_LAYOUT ¶'layout'Constant for view file type 'layout' 
- 
          
          stringTYPE_TEMPLATE ¶'view'Constant for view file type 'template'. 
- 
          
          stringTYPE_VIEW ¶'view'Constant for view file type 'view' 
Property Summary
- 
        $Blocks public @propertyCake\View\ViewBlock
- 
        $Flash public @propertyCake\View\Helper\FlashHelper
- 
        $Form public @propertyCake\View\Helper\FormHelper
- 
        $Html public @propertyCake\View\Helper\HtmlHelper
- 
        $Number public @propertyCake\View\Helper\NumberHelper
- 
        $Paginator public @propertyCake\View\Helper\PaginatorHelper
- 
        $Rss public @propertyCake\View\Helper\RssHelper
- 
        $Session public @propertyCake\View\Helper\SessionHelper
- 
        $Text public @propertyCake\View\Helper\TextHelper
- 
        $Time public @propertyCake\View\Helper\TimeHelper
- 
        $Url public @propertyCake\View\Helper\UrlHelper
- 
        $_current protectedstringThe currently rendering view file. Used for resolving parent files. 
- 
        $_currentType protectedstringCurrently rendering an element. Used for finding parent fragments for elements. 
- 
        $_eventClass protectedstringDefault class name for new event objects. 
- 
        $_eventManager protectedCake\Event\EventManagerInstance of the Cake\Event\EventManager this object is using to dispatch inner events. 
- 
        $_ext protectedstringFile extension. Defaults to CakePHP's template ".ctp". 
- 
        $_helpers protectedCake\View\HelperRegistryHelpers collection 
- 
        $_parents protectedarrayThe names of views and their parents used with View::extend(); 
- 
        $_passedVars protectedarrayList of variables to collect from the associated controller. 
- 
        $_paths protectedarrayHolds an array of paths. 
- 
        $_pathsForPlugin protectedarrayHolds an array of plugin paths. 
- 
        $_responseType protectedstringResponse type. 
- 
        $_specialVars protectedarrayList of special view vars. 
- 
        $_stack protectedarrayContent stack, used for nested templates that all use View::extend(); 
- 
        $_validViewOptions public @propertyarray
- 
        $_viewBlockClass protectedstringViewBlock class. 
- 
        $_viewBuilder protectedCake\View\ViewBuilderThe view builder instance being used. 
- 
        $autoLayout publicboolTurns 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. 
- 
        $elementCache publicstringThe 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. 
- 
        $hasRendered publicboolTrue when the view has been rendered. 
- 
        $helpers publicarrayAn array of names of built-in helpers to include. 
- 
        $layout publicstringThe 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. 
- 
        $layoutPath publicstringXML layouts are located in the xml sub directory of Layouts/
- 
        $name publicstringName of the controller that created the View if any. 
- 
        $passedArgs public deprecatedarrayCurrent passed params. Passed to View from the creating Controller for convenience. 
- 
        $plugin publicstringThe name of the plugin. 
- 
        $request publicCake\Http\ServerRequestAn 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. 
- 
        $response publicCake\Http\ResponseReference to the Response object 
- 
        $subDir publicstringXML views are located in the 'xml' sub directory for controllers' views. 
- 
        $template publicstringThe name of the template file to render. The name specified is the filename in /src/Template/ without the .ctp extension. 
- 
        $templatePath publicstringThe name of the subfolder containing templates for this View. 
- 
        $theme publicstring|nullThe view theme to use. 
- 
        $uuids publicarrayList of generated DOM UUIDs. 
- 
        $view public @propertystring
- 
        $viewClass public deprecatedstringThe name of default View class. 
- 
        $viewPath public @propertystring
- 
        $viewVars publicarrayVariables for the view 
Method Summary
- 
          __construct() publicConstructor 
- 
          __get() publicMagic accessor for helpers. 
- 
          __set() publicMagic setter for deprecated properties. 
- 
          _checkFilePath() protectedCheck that a view file path does not go outside of the defined template paths. 
- 
          _createCell() protectedCreate and configure the cell instance. 
- 
          _elementCache() protectedGenerate the cache configuration options for an element. 
- 
          _evaluate() protectedSandbox method to evaluate a template / view script in. 
- 
          _getElementFileName() protectedFinds an element filename, returns false on failure. 
- 
          _getLayoutFileName() protectedReturns layout filename for this template as a string. 
- 
          _getSubPaths() protectedFind 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. 
- 
          _getViewFileName() protectedReturns 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. 
- 
          _inflectViewFileName() protectedChange the name of a view template file into underscored format. 
- 
          _paths() protectedReturn all possible paths to find view files in order 
- 
          _render() protectedRenders and returns output for given template filename with its array of data. Handles parent/extended templates. 
- 
          _renderElement() protectedRenders an element and fires the before and afterRender callbacks for it and writes to the cache if a cache is used 
- 
          _serialize() protectedSerialize view vars. 
- 
          append() publicAppend to an existing or new block. 
- 
          assign() publicSet the content for a block. This will overwrite any existing content. 
- 
          autoLayout() public deprecatedTurns 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. 
- 
          blocks() publicGet the names of all the existing blocks. 
- 
          cache() publicCreate a cached block of view logic. 
- 
          cell() protectedRenders the given cell. 
- 
          createView() publicConstructs the view class instance based on the current configuration. 
- 
          dispatchEvent() publicWrapper for creating and dispatching events. 
- 
          element() publicRenders a piece of PHP with provided parameters and returns HTML, XML, or any other string. 
- 
          elementExists() publicChecks if an element exists 
- 
          enableAutoLayout() publicTurns 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. 
- 
          end() publicEnd a capturing block. The compliment to View::start() 
- 
          eventManager() public deprecatedReturns the Cake\Event\EventManager manager instance for this object. 
- 
          exists() publicCheck if a block exists 
- 
          extend() publicProvides template or element extension/inheritance. Views can extends a parent view and populate blocks in the parent template. 
- 
          fetch() publicFetch the content for a block. If a block is empty or undefined '' will be returned. 
- 
          get() publicReturns the contents of the given View variable. 
- 
          getCurrentType() publicRetrieve the current view type 
- 
          getEventManager() publicReturns the Cake\Event\EventManager manager instance for this object. 
- 
          getLayout() publicGet 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. 
- 
          getLayoutPath() publicGet path for layout files. 
- 
          getTemplate() publicGet the name of the template file to render. The name specified is the filename in /src/Template/ without the .ctp extension. 
- 
          getTemplatePath() publicGet path for templates files. 
- 
          getTheme() publicGet the current view theme. 
- 
          getVars() publicReturns a list of variables available in the current View context 
- 
          helpers() publicGet the helper registry in use by this View class. 
- 
          initialize() publicInitialization hook method. 
- 
          isAutoLayoutEnabled() publicReturns if CakePHP's conventional mode of applying layout files is enabled. Disabled means that layouts will not be automatically applied to rendered views. 
- 
          layout() public deprecatedGet/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. 
- 
          layoutPath() public deprecatedGet/set path for layout files. 
- 
          loadHelper() publicLoads a helper. Delegates to the HelperRegistry::load()to load the helper
- 
          loadHelpers() publicLoad helpers only if serialization is disabled. 
- 
          log() publicConvenience method to write a message to Log. See Log::write() for more information on writing to logs. 
- 
          pluginSplit() publicSplits 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 
- 
          prepend() publicPrepend to an existing or new block. 
- 
          render() publicRender view template or return serialized data. 
- 
          renderLayout() publicRenders a layout. Returns output from _render(). Returns false on error. Several variables are created for use in layout. 
- 
          requestAction() public deprecatedCalls 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. 
- 
          reset() publicReset the content for a block. This will overwrite any existing content. 
- 
          set() publicSaves a variable or an associative array of variables for use inside a template. 
- 
          setEventManager() publicReturns the Cake\Event\EventManager manager instance for this object. 
- 
          setLayout() publicSet 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. 
- 
          setLayoutPath() publicSet path for layout files. 
- 
          setTemplate() publicSet the name of the template file to render. The name specified is the filename in /src/Template/ without the .ctp extension. 
- 
          setTemplatePath() publicSet path for templates files. 
- 
          setTheme() publicSet the view theme to use. 
- 
          start() publicStart capturing output for a 'block' 
- 
          template() public deprecatedGet/set the name of the template file to render. The name specified is the filename in /src/Template/ without the .ctp extension. 
- 
          templatePath() public deprecatedGet/set path for templates files. 
- 
          theme() public deprecatedThe view theme to use. 
- 
          uuid() publicGenerates a unique, non-random DOM ID for an object, based on the object type and the target URL. 
- 
          viewBuilder() publicGet the view builder being used. 
- 
          viewOptions() publicGet/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().
Method Detail
__construct() ¶ public
__construct(Cake\Http\ServerRequest|null $request = null, Cake\Http\Response|null $response = null, Cake\Event\EventManager|null $eventManager = null, array $viewOptions = [])Constructor
Parameters
- 
                Cake\Http\ServerRequest|null$request optional
- Request instance. 
- 
                Cake\Http\Response|null$response optional
- Response instance. 
- 
                Cake\Event\EventManager|null$eventManager optional
- EventManager instance. 
- 
                array$viewOptions optional
- An array of view options 
__get() ¶ public
__get(string $name): mixedMagic accessor for helpers.
Parameters
- 
                string$name
- Name of the attribute to get. 
Returns
mixed__set() ¶ public
__set(string $name, mixed $value): voidMagic setter for deprecated properties.
Parameters
- 
                string$name
- Name to property. 
- 
                mixed$value
- Value for property. 
Returns
void_checkFilePath() ¶ protected
_checkFilePath(string $file, string $path): stringCheck 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. 
Returns
stringThe file path
Throws
InvalidArgumentException_createCell() ¶ protected
_createCell(string $className, string $action, string $plugin, array $options): Cake\View\CellCreate 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_elementCache() ¶ protected
_elementCache(string $name, array $data, array $options): arrayGenerate the cache configuration options for an element.
Parameters
- 
                string$name
- Element name 
- 
                array$data
- Data 
- 
                array$options
- Element options 
Returns
arrayElement Cache configuration.
_evaluate() ¶ protected
_evaluate(string $viewFile, array $dataForView): stringSandbox method to evaluate a template / view script in.
Parameters
- 
                string$viewFile
- Filename of the view 
- 
                array$dataForView
- Data to include in rendered view. 
Returns
stringRendered output
_getElementFileName() ¶ protected
_getElementFileName(string $name, bool $pluginCheck = true): string|falseFinds an element filename, returns false on failure.
Parameters
- 
                string$name
- The name of the element to find. 
- 
                bool$pluginCheck optional
- if false will ignore the request's plugin if parsed plugin is not loaded
 
Returns
string|falseEither a string to the element filename or false when one can't be found.
_getLayoutFileName() ¶ protected
_getLayoutFileName(string|null $name = null): stringReturns layout filename for this template as a string.
Parameters
- 
                string|null$name optional
- The name of the layout to find. 
Returns
stringFilename for layout file (.ctp).
Throws
Cake\View\Exception\MissingLayoutExceptionwhen a layout cannot be located
_getSubPaths() ¶ protected
_getSubPaths(string $basePath): arrayFind 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
arrayArray with all the templates paths.
_getViewFileName() ¶ protected
_getViewFileName(string|null $name = null): stringReturns 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 optional
- Controller action to find template filename for 
Returns
stringTemplate filename
Throws
Cake\View\Exception\MissingTemplateExceptionwhen a view file could not be found.
_inflectViewFileName() ¶ protected
_inflectViewFileName(string $name): stringChange the name of a view template file into underscored format.
Parameters
- 
                string$name
- Name of file which should be inflected. 
Returns
stringFile name after conversion
_paths() ¶ protected
_paths(string|null $plugin = null, bool $cached = true): arrayReturn all possible paths to find view files in order
Parameters
- 
                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. 
Returns
arraypaths
_render() ¶ protected
_render(string $viewFile, array $data = []): stringRenders 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 optional
- Data to include in rendered view. If empty the current View::$viewVars will be used. 
Returns
stringRendered output
Throws
LogicExceptionWhen a block is left open.
_renderElement() ¶ protected
_renderElement(string $file, array $data, array $options): stringRenders 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_serialize() ¶ protected
_serialize(array|string $serialize): stringSerialize view vars.
Special parameters
_xmlOptions You can set an array of custom options for Xml::fromArray() this way, e.g.
'format' as 'attributes' instead of 'tags'.
Parameters
- 
                array|string$serialize
- The name(s) of the view variable(s) that need(s) to be serialized 
Returns
stringThe serialized data
append() ¶ public
append(string $name, mixed $value = null): $thisAppend to an existing or new block.
Appending to a new block will create the block.
Parameters
- 
                string$name
- Name of the block 
- 
                mixed$value optional
- The content for the block. Value will be type cast to string. 
Returns
$thisSee Also
assign() ¶ public
assign(string $name, mixed $value): $thisSet 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
$thisSee Also
autoLayout() ¶ public
autoLayout(bool|null $autoLayout = null): bool|nullTurns 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
- 
                bool|null$autoLayout optional
- Boolean to turn on/off. If null returns current value. 
Returns
bool|nullblocks() ¶ public
blocks(): arrayGet the names of all the existing blocks.
Returns
arrayAn array containing the blocks.
See Also
cache() ¶ public
cache(callable $block, array $options = []): stringCreate 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 optional
- The options defining the cache key etc. 
Returns
stringThe rendered content.
Throws
RuntimeExceptionWhen $options is lacking a 'key' option.
cell() ¶ protected
cell(string $cell, array $data = [], array $options = []): Cake\View\CellRenders 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::smallListwill invoke- View\Cell\TagCloudCell::smallList(),- displayaction 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 
Returns
Cake\View\CellThe cell instance
Throws
Cake\View\Exception\MissingCellExceptionIf Cell class was not found.
BadMethodCallExceptionIf Cell class does not specified cell action.
createView() ¶ public
createView(string|null $viewClass = null): Cake\View\ViewConstructs the view class instance based on the current configuration.
Parameters
- 
                string|null$viewClass optional
- Optional namespaced class name of the View class to instantiate. 
Returns
Cake\View\ViewThrows
Cake\View\Exception\MissingViewExceptionIf view class was not found.
dispatchEvent() ¶ public
dispatchEvent(string $name, array|null $data = null, object|null $subject = null): Cake\Event\EventWrapper for creating and dispatching events.
Returns a dispatched event.
Parameters
- 
                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). 
Returns
Cake\Event\Eventelement() ¶ public
element(string $name, array $data = [], array $options = []): stringRenders 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.templateto 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
 
Returns
stringRendered Element
Throws
Cake\View\Exception\MissingElementExceptionWhen an element is missing and `ignoreMissing` is false.
elementExists() ¶ public
elementExists(string $name): boolChecks if an element exists
Parameters
- 
                string$name
- Name of template file in the /src/Template/Element/ folder, or - MyPlugin.templateto check the template element from MyPlugin. If the element is not found in the plugin, the normal view path cascade will be searched.
Returns
boolSuccess
enableAutoLayout() ¶ public
enableAutoLayout(bool $enable = true): $thisTurns 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
$thisend() ¶ public
end(): $thisEnd a capturing block. The compliment to View::start()
Returns
$thisSee Also
eventManager() ¶ public
eventManager(Cake\Event\EventManager|null $eventManager = null): Cake\Event\EventManagerReturns 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 optional
- the eventManager to set 
Returns
Cake\Event\EventManagerexists() ¶ public
exists(string $name): boolCheck if a block exists
Parameters
- 
                string$name
- Name of the block 
Returns
boolextend() ¶ public
extend(string $name): $thisProvides 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. 
Returns
$thisThrows
LogicExceptionwhen you extend a template with itself or make extend loops.
LogicExceptionwhen you extend an element which doesn't exist
fetch() ¶ public
fetch(string $name, string $default = ''): stringFetch the content for a block. If a block is empty or undefined '' will be returned.
Parameters
- 
                string$name
- Name of the block 
- 
                string$default optional
- Default text 
Returns
stringThe block content or $default if the block does not exist.
See Also
get() ¶ public
get(string $var, mixed $default = null): mixedReturns the contents of the given View variable.
Parameters
- 
                string$var
- The view var you want the contents of. 
- 
                mixed$default optional
- The default/fallback content of $var. 
Returns
mixedThe content of the named var if its set, otherwise $default.
getEventManager() ¶ public
getEventManager(): Cake\Event\EventManagerReturns 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\EventManagergetLayout() ¶ public
getLayout(): stringGet 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
stringgetTemplate() ¶ public
getTemplate(): stringGet the name of the template file to render. The name specified is the
filename in /src/Template/
Returns
stringgetVars() ¶ public
getVars(): arrayReturns a list of variables available in the current View context
Returns
arrayArray of the set view variable names.
helpers() ¶ public
helpers(): Cake\View\HelperRegistryGet the helper registry in use by this View class.
Returns
Cake\View\HelperRegistryinitialize() ¶ public
initialize(): voidInitialization 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.
Returns
voidisAutoLayoutEnabled() ¶ public
isAutoLayoutEnabled(): boolReturns if CakePHP's conventional mode of applying layout files is enabled. Disabled means that layouts will not be automatically applied to rendered views.
Returns
boollayout() ¶ public
layout(string|null $name = null): string|nullGet/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 optional
- Layout file name to set. If null returns current name. 
Returns
string|nulllayoutPath() ¶ public
layoutPath(string|null $path = null): string|nullGet/set path for layout files.
Parameters
- 
                string|null$path optional
- Path for layout files. If null returns current path. 
Returns
string|nullloadHelper() ¶ public
loadHelper(string $name, array $config = []): Cake\View\HelperLoads a helper. Delegates to the HelperRegistry::load() to load the helper
Parameters
- 
                string$name
- Name of the helper to load. 
- 
                array$config optional
- Settings for the helper 
Returns
Cake\View\Helpera constructed helper object.
See Also
loadHelpers() ¶ public
loadHelpers(): voidLoad helpers only if serialization is disabled.
Returns
voidlog() ¶ public
log(mixed $msg, int|string $level = LogLevel::ERROR, string|array $context = []): boolConvenience method to write a message to Log. See Log::write() for more information on writing to logs.
Parameters
- 
                mixed$msg
- Log message. 
- 
                int|string$level optional
- Error level. 
- 
                string|array$context optional
- Additional log data relevant to this message. 
Returns
boolSuccess of log write.
pluginSplit() ¶ public
pluginSplit(string $name, bool $fallback = true): arraySplits 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. 
- 
                bool$fallback optional
- If true uses the plugin set in the current Request when parsed plugin is not loaded 
Returns
arrayArray with 2 indexes. 0 => plugin name, 1 => filename
prepend() ¶ public
prepend(string $name, mixed $value): $thisPrepend 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
$thisSee Also
render() ¶ public
render(string|false|null $view = null, string|null $layout = null): string|nullRender view template or return serialized data.
Special parameters
_serialize To convert a set of view variables into a serialized form.
Its value can be a string for single variable name or array for multiple
names. If true all view variables will be serialized. If unset normal
view template will be rendered.
Parameters
- 
                string|false|null$view optional
- The view being rendered. 
- 
                string|null$layout optional
- The layout being rendered. 
Returns
string|nullThe rendered view.
renderLayout() ¶ public
renderLayout(string $content, string|null $layout = null): mixedRenders 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 optional
- Layout name 
Returns
mixedRendered output, or false on error
Throws
Cake\Core\Exception\Exceptionif there is an error in the view.
requestAction() ¶ public
requestAction(string|array $url, array $extra = []): mixedCalls 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 optional
- 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
mixedBoolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
reset() ¶ public
reset(string $name): $thisReset the content for a block. This will overwrite any existing content.
Parameters
- 
                string$name
- Name of the block 
Returns
$thisSee Also
set() ¶ public
set(string|array $name, mixed $value = null): $thisSaves 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 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. 
Returns
$thissetEventManager() ¶ public
setEventManager(Cake\Event\EventManager $eventManager): $thisReturns 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
$thissetLayout() ¶ public
setLayout(string $name): $thisSet 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
$thissetLayoutPath() ¶ public
setLayoutPath(string $path): $thisSet path for layout files.
Parameters
- 
                string$path
- Path for layout files. 
Returns
$thissetTemplate() ¶ public
setTemplate(string $name): $thisSet the name of the template file to render. The name specified is the
filename in /src/Template/
Parameters
- 
                string$name
- Template file name to set. 
Returns
$thissetTemplatePath() ¶ public
setTemplatePath(string $path): $thisSet path for templates files.
Parameters
- 
                string$path
- Path for template files. 
Returns
$thissetTheme() ¶ public
setTheme(string|null $theme): $thisSet the view theme to use.
Parameters
- 
                string|null$theme
- Theme name. 
Returns
$thisstart() ¶ public
start(string $name): $thisStart 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
$thisSee Also
template() ¶ public
template(string|null $name = null): string|nullGet/set the name of the template file to render. The name specified is the
filename in /src/Template/
Parameters
- 
                string|null$name optional
- Template file name to set. If null returns current name. 
Returns
string|nulltemplatePath() ¶ public
templatePath(string|null $path = null): string|nullGet/set path for templates files.
Parameters
- 
                string|null$path optional
- Path for template files. If null returns current path. 
Returns
string|nulltheme() ¶ public
theme(string|null $theme = null): string|nullThe view theme to use.
Parameters
- 
                string|null$theme optional
- Theme name. If null returns current theme. 
Returns
string|nulluuid() ¶ public
uuid(string $object, string $url): stringGenerates 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
stringviewBuilder() ¶ public
viewBuilder(): Cake\View\ViewBuilderGet the view builder being used.
Returns
Cake\View\ViewBuilderviewOptions() ¶ public
viewOptions(string|array|null $options = null, bool $merge = true): arrayGet/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 optional
- string or array of string to be appended to _validViewOptions. 
- 
                bool$merge optional
- Whether to merge with or override existing valid View options. Defaults to - true.
Returns
arrayThe updated view options as an array.
Property Detail
$_current ¶ protected
The currently rendering view file. Used for resolving parent files.
Type
string$_currentType ¶ protected
Currently rendering an element. Used for finding parent fragments for elements.
Type
string$_eventManager ¶ protected
Instance of the Cake\Event\EventManager this object is using to dispatch inner events.
Type
Cake\Event\EventManager$_stack ¶ protected
Content stack, used for nested templates that all use View::extend();
Type
array$autoLayout ¶ 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 templates.
Type
bool$elementCache ¶ public
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$layout ¶ public
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$passedArgs ¶ public deprecated
Current passed params. Passed to View from the creating Controller for convenience.
Type
array$request ¶ public
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$subDir ¶ public
XML views are located in the 'xml' sub directory for controllers' views.
Type
string$template ¶ public
The name of the template file to render. The name specified
is the filename in /src/Template/
Type
string