$helpers
$helpers : array
List of helpers used by this helper
Html Helper class for easy use of HTML widgets.
HtmlHelper encloses all methods needed while working with HTML pages.
None found |
$response : \Cake\Http\Response
Reference to the Response object
None found |
$_templater : \Cake\View\StringTemplate
StringTemplate instance.
None found |
None found |
$_View : \Cake\View\View
The View instance this helper is attached to
None found |
None found |
$_configInitialized : boolean
Whether the config property has already been configured with defaults
None found |
None found |
$_includedAssets : array
Names of script & css files that have been included once
None found |
$_scriptBlockOptions : array
Options for the currently opened script block buffer if any.
None found |
setTemplates(array $templates) : $this
Sets templates to use.
array | $templates | Templates to be added. |
None found |
getTemplates(string|null $template = null) : string|array
Gets templates to use or a specific template.
string|null | $template | String for reading a specific template, null for all. |
None found |
templates(string|null|array $templates = null) : $this|string|array
Gets/sets templates to use.
string|null|array | $templates | null or string allow reading templates. An array allows templates to be added. |
None found |
formatTemplate(string $name, array $data) : string
Formats a template string with $data
string | $name | The template name. |
array | $data | The data to insert. |
None found |
templater() : \Cake\View\StringTemplate
Returns the templater instance.
None found |
__construct(\Cake\View\View $View, array $config = array())
Constructor
templates
Either a filename to a config containing templates.
Or an array of templates to load. See Cake\View\StringTemplate for
template formatting.Using the templates
option you can redefine the tag HtmlHelper will use.
\Cake\View\View | $View | The View this helper is being attached to. |
array | $config | Configuration settings for the helper. |
None found |
__call(string $method, array $params) : void
Provide non fatal errors on missing method calls.
string | $method | Method to invoke |
array | $params | Array of params for the method. |
None found |
__get(string $name) : \Cake\View\Helper|null
Lazy loads helpers.
string | $name | Name of the property being accessed. |
Helper instance if helper with provided name exists
None found |
__set(string $name, mixed $value) : void
Magic setter for removed properties.
string | $name | Property name. |
mixed | $value | Value to set. |
None found |
getView() : \Cake\View\View
Get the view instance this helper is bound to.
The bound view instance.
None found |
addClass(array $options = array(), string|null $class = null, string $key = 'class') : array
Adds the given class to the element options
array | $options | Array options/attributes to add a class to |
string|null | $class | The class name being added. |
string | $key | the key to use for class. |
Array of options with $key set.
None found |
implementedEvents() : array
Event listeners.
By defining one of the callback methods a helper is assumed to be interested in the related event.
Override this method if you need to add non-conventional event listeners. Or if you want helpers to listen to non-standard events.
None found |
initialize(array $config) : void
Constructor hook method.
Implement this method to avoid having to overwrite the constructor and call parent.
array | $config | The configuration settings provided to this helper. |
None found |
__debugInfo() : array
Returns an array that can be used to describe the internal state of this object.
None found |
setConfig(string|array $key, mixed|null $value = null, boolean $merge = true) : $this
Sets the config.
Setting a specific value:
$this->setConfig('key', $value);
Setting a nested value:
$this->setConfig('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->setConfig(['one' => 'value', 'another' => 'value']);
string|array | $key | The key to set, or a complete array of configs. |
mixed|null | $value | The value to set. |
boolean | $merge | Whether to recursively merge or overwrite existing config, defaults to true. |
When trying to set a key that is invalid.
None found |
getConfig(string|null $key = null, mixed $default = null) : mixed
Returns the config.
Reading the whole config:
$this->getConfig();
Reading a specific value:
$this->getConfig('key');
Reading a nested value:
$this->getConfig('some.nested.key');
Reading with default value:
$this->getConfig('some-key', 'default-value');
string|null | $key | The key to get or null for the whole config. |
mixed | $default | The return value when the key does not exist. |
Config value being read.
None found |
config(string|array|null $key = null, mixed|null $value = null, boolean $merge = true) : mixed
Gets/Sets the config.
Reading the whole config:
$this->config();
Reading a specific value:
$this->config('key');
Reading a nested value:
$this->config('some.nested.key');
Setting a specific value:
$this->config('key', $value);
Setting a nested value:
$this->config('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->config(['one' => 'value', 'another' => 'value']);
string|array|null | $key | The key to get/set, or a complete array of configs. |
mixed|null | $value | The value to set. |
boolean | $merge | Whether to recursively merge or overwrite existing config, defaults to true. |
When trying to set a key that is invalid.
Config value being read, or the object itself on write operations.
None found |
configShallow(string|array $key, mixed|null $value = null) : $this
Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.
Setting a specific value:
$this->configShallow('key', $value);
Setting a nested value:
$this->configShallow('some.nested.key', $value);
Updating multiple config settings at the same time:
$this->configShallow(['one' => 'value', 'another' => 'value']);
string|array | $key | The key to set, or a complete array of configs. |
mixed|null | $value | The value to set. |
None found |
addCrumb(string $name, string|array|null $link = null, array $options = array()) : $this
Adds a link to the breadcrumbs array.
string | $name | Text for link |
string|array|null | $link | URL for link (if empty it won't be a link) |
array | $options | Link attributes e.g. ['id' => 'selected'] |
None found |
docType(string $type = 'html5') : string|null
Returns a doctype string.
Possible doctypes:
string | $type | Doctype to use. |
Doctype string
None found |
meta(string|array $type, string|array|null $content = null, array $options = array()) : string|null
Creates a link to an external resource and handles basic meta tags
Create a meta tag that is output inline:
$this->Html->meta('icon', 'favicon.ico');
Append the meta tag to custom view block "meta":
$this->Html->meta('description', 'A great page', ['block' => true]);
Append the meta tag to custom view block:
$this->Html->meta('description', 'A great page', ['block' => 'metaTags']);
Create a custom meta tag:
$this->Html->meta(['property' => 'og:site_name', 'content' => 'CakePHP']);
block
- Set to true to append output to view block "meta" or provide
custom block name.string|array | $type | The title of the external resource, Or an array of attributes for a custom meta tag. |
string|array|null | $content | The address of the external resource or string for content attribute |
array | $options | Other attributes for the generated tag. If the type attribute is html, rss, atom, or icon, the mime-type is returned. |
A completed <link />
element, or null if the element was sent to a block.
None found |
charset(string|null $charset = null) : string
Returns a charset META-tag.
string|null | $charset | The character set to be used in the meta tag. If empty, The App.encoding value will be used. Example: "utf-8". |
A meta tag containing the specified character set.
None found |
link(string|array $title, string|array|null $url = null, array $options = array()) : string
Creates an HTML link.
If $url starts with "http://" this is treated as an external link. Else, it is treated as a path to controller/action and parsed with the UrlHelper::build() method.
If the $url is empty, $title is used instead.
escape
Set to false to disable escaping of title and attributes.escapeTitle
Set to false to disable escaping of title. Takes precedence
over value of escape
)confirm
JavaScript confirmation message.string|array | $title | The content to be wrapped by |
string|array|null | $url | Cake-relative URL or array of URL parameters, or external URL (starts with http://) |
array | $options | Array of options and HTML attributes. |
An <a />
element.
None found |
css(string|array $path, array $options = array()) : string|null
Creates a link element for CSS stylesheets.
Include one CSS file:
echo $this->Html->css('styles.css');
Include multiple CSS files:
echo $this->Html->css(['one.css', 'two.css']);
Add the stylesheet to view block "css":
$this->Html->css('styles.css', ['block' => true]);
Add the stylesheet to a custom block:
$this->Html->css('styles.css', ['block' => 'layoutCss']);
block
Set to true to append output to view block "css" or provide
custom block name.once
Whether or not the css file should be checked for uniqueness. If true css
files will only be included once, use false to allow the same
css to be included more than once per request.plugin
False value will prevent parsing path as a pluginrel
Defaults to 'stylesheet'. If equal to 'import' the stylesheet will be imported.fullBase
If true the URL will get a full address for the css file.string|array | $path | The name of a CSS style sheet or an array containing names of
CSS stylesheets. If |
array | $options | Array of options and HTML arguments. |
CSS <link />
or <style />
tag, depending on the type of link.
None found |
script(string|array $url, array $options = array()) : string|null
Returns one or many `<script>` tags depending on the number of scripts given.
If the filename is prefixed with "/", the path will be relative to the base path of your application. Otherwise, the path will be relative to your JavaScript path, usually webroot/js.
Include one script file:
echo $this->Html->script('styles.js');
Include multiple script files:
echo $this->Html->script(['one.js', 'two.js']);
Add the script file to a custom block:
$this->Html->script('styles.js', ['block' => 'bodyScript']);
block
Set to true to append output to view block "script" or provide
custom block name.once
Whether or not the script should be checked for uniqueness. If true scripts will only be
included once, use false to allow the same script to be included more than once per request.plugin
False value will prevent parsing path as a pluginfullBase
If true the url will get a full address for the script file.string|array | $url | String or array of javascript files to include |
array | $options | Array of options, and html attributes see above. |
String of <script />
tags or null if block is specified in options
or if $once is true and the file has been included before.
None found |
scriptBlock(string $script, array $options = array()) : string|null
Wrap $script in a script tag.
safe
(boolean) Whether or not the $script should be wrapped in <![CDATA[ ]]>
.
Defaults to false
.block
Set to true to append output to view block "script" or provide
custom block name.string | $script | The script to wrap |
array | $options | The options to use. Options not listed above will be treated as HTML attributes. |
String or null depending on the value of $options['block']
None found |
scriptStart(array $options = array()) : void
Begin a script block that captures output until HtmlHelper::scriptEnd() is called. This capturing block will capture all output between the methods and create a scriptBlock from it.
safe
(boolean) Whether or not the $script should be wrapped in <![CDATA[ ]]>
.
See scriptBlock().block
Set to true to append output to view block "script" or provide
custom block name.array | $options | Options for the code block. |
None found |
scriptEnd() : string|null
End a Buffered section of JavaScript capturing.
Generates a script tag inline or appends to specified view block depending on the settings used when the scriptBlock was started
Depending on the settings of scriptStart() either a script tag or null
None found |
style(array $data, boolean $oneLine = true) : string
Builds CSS style data from an array of CSS properties
echo $this->Html->style(['margin' => '10px', 'padding' => '10px'], true);
// creates
'margin:10px;padding:10px;'
array | $data | Style data array, keys will be used as property names, values as property values. |
boolean | $oneLine | Whether or not the style block should be displayed on one line. |
CSS styling data
None found |
getCrumbs(string $separator = '»', string|array|boolean $startText = false) : string|null
Returns the breadcrumb trail as a sequence of »-separated links.
If $startText
is an array, the accepted keys are:
text
Define the text/content for the link.url
Define the target of the created link.All other keys will be passed to HtmlHelper::link() as the $options
parameter.
string | $separator | Text to separate crumbs. |
string|array|boolean | $startText | This will be the first crumb, if false it defaults to first crumb in array. Can also be an array, see above for details. |
Composed bread crumbs
None found |
getCrumbList(array $options = array(), string|array|boolean $startText = false) : string|null
Returns breadcrumbs as a (x)html list
This method uses HtmlHelper::tag() to generate list and its elements. Works similar to HtmlHelper::getCrumbs(), so it uses options which every crumb was added with.
separator
Separator content to insert in between breadcrumbs, defaults to ''firstClass
Class for wrapper tag on the first breadcrumb, defaults to 'first'lastClass
Class for wrapper tag on current active page, defaults to 'last'array | $options | Array of HTML attributes to apply to the generated list elements. |
string|array|boolean | $startText | This will be the first crumb, if false it defaults to first crumb in array. Can
also be an array, see |
Breadcrumbs HTML list.
None found |
image(string|array $path, array $options = array()) : string
Creates a formatted IMG element.
This method will set an empty alt attribute if one is not supplied.
Create a regular image:
echo $this->Html->image('cake_icon.png', ['alt' => 'CakePHP']);
Create an image link:
echo $this->Html->image('cake_icon.png', ['alt' => 'CakePHP', 'url' => 'https://cakephp.org']);
url
If provided an image link will be generated and the link will point at
$options['url']
.fullBase
If true the src attribute will get a full address for the image file.plugin
False value will prevent parsing path as a pluginstring|array | $path | Path to the image file, relative to the app/webroot/img/ directory. |
array | $options | Array of HTML attributes. See above for special options. |
completed img tag
None found |
tableHeaders(array $names, array|null $trOptions = null, array|null $thOptions = null) : string
Returns a row of formatted and named TABLE headers.
array | $names | Array of tablenames. Each tablename also can be a key that points to an array with a set of attributes to its specific tag |
array|null | $trOptions | HTML options for TR elements. |
array|null | $thOptions | HTML options for TH elements. |
Completed table headers
None found |
tableCells(array|string $data, array|boolean|null $oddTrOptions = null, array|boolean|null $evenTrOptions = null, boolean $useCount = false, boolean $continueOddEven = true) : string
Returns a formatted string of table rows (TR's with TD's in them).
array|string | $data | Array of table data |
array|boolean|null | $oddTrOptions | HTML options for odd TR elements if true useCount is used |
array|boolean|null | $evenTrOptions | HTML options for even TR elements |
boolean | $useCount | adds class "column-$i" |
boolean | $continueOddEven | If false, will use a non-static $count variable, so that the odd/even count is reset to zero just for that call. |
Formatted HTML
None found |
tableRow(string $content, array $options = array()) : string
Renders a single table row (A TR with attributes).
string | $content | The content of the row. |
array | $options | HTML attributes. |
None found |
tableCell(string $content, array $options = array()) : string
Renders a single table cell (A TD with attributes).
string | $content | The content of the cell. |
array | $options | HTML attributes. |
None found |
tag(string $name, string|null $text = null, array $options = array()) : string
Returns a formatted block tag, i.e DIV, SPAN, P.
escape
Whether or not the contents should be html_entity escaped.string | $name | Tag name. |
string|null | $text | String content that will appear inside the div element. If null, only a start tag will be printed |
array | $options | Additional HTML attributes of the DIV tag, see above. |
The formatted tag element
None found |
div(string|null $class = null, string|null $text = null, array $options = array()) : string
Returns a formatted DIV tag for HTML FORMs.
escape
Whether or not the contents should be html_entity escaped.string|null | $class | CSS class name of the div element. |
string|null | $text | String content that will appear inside the div element. If null, only a start tag will be printed |
array | $options | Additional HTML attributes of the DIV tag |
The formatted DIV element
None found |
para(string $class, string $text, array $options = array()) : string
Returns a formatted P tag.
escape
Whether or not the contents should be html_entity escaped.string | $class | CSS class name of the p element. |
string | $text | String content that will appear inside the p element. |
array | $options | Additional HTML attributes of the P tag |
The formatted P element
None found |
media(string|array $path, array $options = array()) : string
Returns an audio/video element
Using an audio file:
echo $this->Html->media('audio.mp3', ['fullBase' => true]);
Outputs:
<video src="http://www.somehost.com/files/audio.mp3">Fallback text</video>
Using a video file:
echo $this->Html->media('video.mp4', ['text' => 'Fallback text']);
Outputs:
<video src="/files/video.mp4">Fallback text</video>
Using multiple video files:
echo $this->Html->media(
['video.mp4', ['src' => 'video.ogv', 'type' => "video/ogg; codecs='theora, vorbis'"]],
['tag' => 'video', 'autoplay']
);
Outputs:
<video autoplay="autoplay">
<source src="/files/video.mp4" type="video/mp4"/>
<source src="/files/video.ogv" type="video/ogv; codecs='theora, vorbis'"/>
</video>
tag
Type of media element to generate, either "audio" or "video".
If tag is not provided it's guessed based on file's mime type.text
Text to include inside the audio/video tagpathPrefix
Path prefix to use for relative URLs, defaults to 'files/'fullBase
If provided the src attribute will get a full address including domain namestring|array | $path | Path to the video file, relative to the webroot/{$options['pathPrefix']} directory.
Or an array where each item itself can be a path string or an associate array containing keys |
array | $options | Array of HTML attributes, and special options above. |
Generated media element
None found |
nestedList(array $list, array $options = array(), array $itemOptions = array()) : string
Build a nested list (UL/OL) out of an associative array.
Options for $options:
tag
- Type of list tag to use (ol/ul)Options for $itemOptions:
even
- Class to use for even rows.odd
- Class to use for odd rows.array | $list | Set of elements to list |
array | $options | Options and additional HTML attributes of the list (ol/ul) tag. |
array | $itemOptions | Options and additional HTML attributes of the list item (LI) tag. |
The nested list
None found |
_confirm(string $message, string $okCode, string $cancelCode = '', array $options = array()) : string
Returns a string to be used as onclick handler for confirm dialogs.
string | $message | Message to be displayed |
string | $okCode | Code to be executed after user chose 'OK' |
string | $cancelCode | Code to be executed after user chose 'Cancel' |
array | $options | Array of options |
onclick JS code
None found |
_cleanConfirmMessage(string $message) : mixed
Returns a string read to be used in confirm()
string | $message | The message to clean |
None found |
_configRead(string|null $key) : mixed
Reads a config key.
string|null | $key | Key to read. |
None found |
_configWrite(string|array $key, mixed $value, boolean|string $merge = false) : void
Writes a config key.
string|array | $key | Key to write to. |
mixed | $value | Value to write. |
boolean|string | $merge | True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false. |
if attempting to clobber existing config
None found |
_configDelete(string $key) : void
Deletes a single config key.
string | $key | Key to delete. |
if attempting to clobber existing config
None found |
_prepareCrumbs(string|array|boolean $startText, boolean $escape = true) : array
Prepends startText to crumbs array if set
string|array|boolean | $startText | Text to prepend |
boolean | $escape | If the output should be escaped or not |
Crumb list including startText (if provided)
None found |
_renderCells(array $line, boolean $useCount = false) : array<mixed,string>
Renders cells for a row of a table.
This is a helper method for tableCells(). Overload this method as you need to change the behavior of the cell rendering.
array | $line | Line data to render. |
boolean | $useCount | Renders the count into the row. Default is false. |
None found |
_nestedListItem(array $items, array $options, array $itemOptions) : string
Internal function to build a nested list (UL/OL) out of an associative array.
array | $items | Set of elements to list. |
array | $options | Additional HTML attributes of the list (ol/ul) tag. |
array | $itemOptions | Options and additional HTML attributes of the list item (LI) tag. |
The nested list element
None found |