Html Helper class for easy use of HTML widgets.
HtmlHelper encloses all methods needed while working with HTML pages.
__construct( Cake\View\View $View , array $config [] )
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
$config
optional [] Cake\View\Helper::__construct()
_nestedListItem( array $items , array $options , array $itemOptions )
Internal function to build a nested list (UL/OL) out of an associative array.
$items
$options
$itemOptions
string
Cake\View\Helper\HtmlHelper::nestedList()
_prepareCrumbs( string|array|boolean $startText , boolean $escape true )
Prepends startText to crumbs array if set
$startText
$escape
optional true array
addCrumb( string $name , string|null $link null , array $options [] )
Adds a link to the breadcrumbs array.
$name
$link
optional null $options
optional [] mixed
charset( string|null $charset null )
Returns a charset META-tag.
$charset
optional null string
css( string|array $path , array $options [] )
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.$path
$path
is prefixed with '/', the path will be relative to the webroot of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css.$options
optional [] string|null
div( string $class null , string $text null , array $options [] )
Returns a formatted DIV tag for HTML FORMs.
escape
Whether or not the contents should be html_entity escaped.$class
optional null $text
optional null $options
optional [] string
docType( string $type 'html5' )
Returns a doctype string.
Possible doctypes:
- html4-strict: HTML4 Strict. - html4-trans: HTML4 Transitional. - html4-frame: HTML4 Frameset. - html5: HTML5. Default value. - xhtml-strict: XHTML1 Strict. - xhtml-trans: XHTML1 Transitional. - xhtml-frame: XHTML1 Frameset. - xhtml11: XHTML1.1.
$type
optional 'html5' string|null
getCrumbList( array $options [] , string|array|boolean $startText false )
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'$options
optional [] $startText
optional false HtmlHelper::getCrumbs
for details.string|null
getCrumbs( string $separator '»' , string|array|boolean $startText false )
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.
$separator
optional '»' $startText
optional false string|null
image( string $path , array $options [] )
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' => 'http://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 plugin$path
$options
optional [] string
implementedEvents( )
Event listeners.
array
Cake\View\Helper::implementedEvents()
link( string $title , string|array|null $url null , array $options [] )
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.$title
$url
optional null $options
optional [] string
<a />
element.media( string|array $path , array $options [] )
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 name$path
src
and type
$options
optional [] string
meta( string|array $type , string|array|null $content null , array $options [] )
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.$type
$content
optional null $options
optional [] string
<link />
element.nestedList( array $list , array $options [] , array $itemOptions [] )
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.$list
$options
optional [] $itemOptions
optional [] string
para( string $class , string $text , array $options [] )
Returns a formatted P tag.
escape
Whether or not the contents should be html_entity escaped.$class
$text
$options
optional [] string
script( string|array $url , array $options [] )
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.$url
$options
optional [] string|null
<script />
tags or null if block is specified in options or if $once is true and the file has been included before.scriptBlock( string $script , array $options [] )
Wrap $script in a script tag.
safe
(boolean) Whether or not the $script should be wrapped in <![CDATA[ ]]>block
Set to true to append output to view block "script" or provide custom block name.$script
$options
optional [] string|null
$options['block']
scriptEnd( )
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
string|null
scriptStart( array $options [] )
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
Whether the code block should contain a CDATAblock
Set to true to append output to view block "script" or provide custom block name.$options
optional [] style( array $data , boolean $oneLine true )
Builds CSS style data from an array of CSS properties
echo $this->Html->style(['margin' => '10px', 'padding' => '10px'], true); // creates 'margin:10px;padding:10px;'
$data
$oneLine
optional true string
tableCells( array|string $data , array|boolean|null $oddTrOptions null , array|boolean|null $evenTrOptions null , boolean $useCount false , boolean $continueOddEven true )
Returns a formatted string of table rows (TR's with TD's in them).
$data
$oddTrOptions
optional null $evenTrOptions
optional null $useCount
optional false $continueOddEven
optional true string
tableHeaders( array $names , array $trOptions null , array $thOptions null )
Returns a row of formatted and named TABLE headers.
$names
$trOptions
optional null $thOptions
optional null string
tag( string $name , string $text null , array $options [] )
Returns a formatted block tag, i.e DIV, SPAN, P.
escape
Whether or not the contents should be html_entity escaped.$name
$text
optional null $options
optional [] string
__call( string $method , array $params )
Provide non fatal errors on missing method calls.
$method
$params
__debugInfo( )
Returns an array that can be used to describe the internal state of this object.
array
__get( string $name )
Lazy loads helpers.
$name
Cake\View\Helper|null
_confirm( string $message , string $okCode , string $cancelCode '' , array $options [] )
Returns a string to be used as onclick handler for confirm dialogs.
$message
$okCode
$cancelCode
optional '' $options
optional [] string
addClass( array $options [] , string $class null , string $key 'class' )
Adds the given class to the element options
$options
optional [] $class
optional null $key
optional 'class' array
formatTemplate( string $name , array $data )
Format a template string with $data
$name
$data
string
templater( )
templater
Cake\View\StringTemplate
templates( string|null|array $templates null )
Get/set templates to use.
$templates
optional null mixed
_configDelete( string $key )
Delete a single config key
$key
Cake\Core\Exception\Exception
_configRead( string|null $key )
Read a config variable
$key
mixed
_configWrite( string|array $key , mixed $value , boolean|string $merge false )
Write a config variable
$key
$value
$merge
optional false Cake\Core\Exception\Exception
config( string|array|null $key null , mixed|null $value null , boolean $merge true )
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']);
$key
optional null $value
optional null $merge
optional true mixed
Cake\Core\Exception\Exception
configShallow( string|array $key , mixed|null $value null )
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->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']);
$key
$value
optional null mixed
public array
Holds the fields ['field_name' => ['type' => 'string', 'length' => 100]], primaryKey and validates ['field_name']
[]
protected boolean
Whether the config property has already been configured with defaults
false
public Cake\View\Helper\UrlHelper
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/3.1/class-Cake.View.Helper.HtmlHelper.html