Class HtmlHelper

Html Helper class for easy use of HTML widgets.

HtmlHelper encloses all methods needed while working with HTML pages.

Object
Extended by Helper
Extended by AppHelper
Extended by HtmlHelper
Package: Cake\View\Helper
Link: http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/HtmlHelper.php

Properties summary

Inherited Properties

Method Summary

  • __construct() public
    Constructor
  • _nestedListItem() protected
    Internal function to build a nested list (UL/OL) out of an associative array.
  • _prepareCrumbs() protected
    Prepends startText to crumbs array if set
  • addCrumb() public
    Adds a link to the breadcrumbs array.
  • charset() public
    Returns a charset META-tag.
  • css() public
    Creates a link element for CSS stylesheets.
  • div() public
    Returns a formatted DIV tag for HTML FORMs.
  • docType() public
    Returns a doctype string.
  • Returns breadcrumbs as a (x)html list
  • getCrumbs() public
    Returns the breadcrumb trail as a sequence of »-separated links.
  • image() public
    Creates a formatted IMG element.
  • link() public
    Creates an HTML link.
  • loadConfig() public
    Load Html tag configuration.
  • media() public
    Returns an audio/video element
  • meta() public
    Creates a link to an external resource and handles basic meta tags
  • nestedList() public
    Build a nested list (UL/OL) out of an associative array.
  • para() public
    Returns a formatted P tag.
  • script() public
    Returns one or many <script> tags depending on the number of scripts given.
  • scriptBlock() public
    Wrap $script in a script tag.
  • scriptEnd() public

    End a Buffered section of JavaScript capturing. Generates a script tag inline or in $scripts_for_layout depending on the settings used when the scriptBlock was started

  • scriptStart() public

    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.

  • style() public
    Builds CSS style data from an array of CSS properties
  • tableCells() public
    Returns a formatted string of table rows (TR's with TD's in them).
  • Returns a row of formatted and named TABLE headers.
  • tag() public
    Returns a formatted block tag, i.e DIV, SPAN, P.
  • useTag() public
    Returns a formatted existent block of $tags

Method Detail

__construct()source public

__construct( View $View , array $settings array() )

Constructor

Settings

  • configFile A file containing an array of tags you wish to redefine.

Customizing tag sets

Using the configFile option you can redefine the tag HtmlHelper will use. The file named should be compatible with HtmlHelper::loadConfig().

Parameters

View $View
The View this helper is being attached to.
array $settings optional array()
Configuration settings for the helper.

Overrides

Helper::__construct()

_nestedListItem()source protected

_nestedListItem( array $items , array $options , array $itemOptions , string $tag )

Internal function to build a nested list (UL/OL) out of an associative array.

Parameters

array $items
Set of elements to list
array $options
Additional HTML attributes of the list (ol/ul) tag
array $itemOptions
Additional HTML attributes of the list item (LI) tag
string $tag
Type of list tag to use (ol/ul)

Returns

string
The nested list element

See

HtmlHelper::nestedList()

_prepareCrumbs()source protected

_prepareCrumbs( string $startText , boolean $escape true )

Prepends startText to crumbs array if set

Parameters

string $startText
Text to prepend
boolean $escape optional true
If the output should be escaped or not

Returns

array
Crumb list including startText (if provided)

addCrumb()source public

addCrumb( string $name , string $link null , string|array $options null )

Adds a link to the breadcrumbs array.

Parameters

string $name
Text for link
string $link optional null
URL for link (if empty it won't be a link)
string|array $options optional null
Link attributes e.g. array('id' => 'selected')

Returns

HtmlHelper

See

HtmlHelper::link() for details on $options that can be used.

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper

charset()source public

charset( string $charset null )

Returns a charset META-tag.

Parameters

string $charset optional null

The character set to be used in the meta tag. If empty, The App.encoding value will be used. Example: "utf-8".

Returns

string
A meta tag containing the specified character set.

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::charset

css()source public

css( string|array $path , array $options array() )

Creates a link element for CSS stylesheets.

Usage

Include one CSS file:

echo $this->Html->css('styles.css');

Include multiple CSS files:

echo $this->Html->css(array('one.css', 'two.css'));

Add the stylesheet to the $scripts_for_layout layout var:

$this->Html->css('styles.css', array('inline' => false));

Add the stylesheet to a custom block:

$this->Html->css('styles.css', array('block' => 'layoutCss'));

Options

  • inline If set to false, the generated tag will be appended to the 'css' block, and included in the $scripts_for_layout layout variable. Defaults to true.
  • 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.
  • block Set the name of the block link/style tag will be appended to. This overrides the inline option.
  • plugin False value will prevent parsing path as a plugin
  • rel 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.

Parameters

string|array $path

The name of a CSS style sheet or an array containing names of CSS stylesheets. If $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.

array $options optional array()
Array of options and HTML arguments.

Returns

string
CSS <link /> or <style /> tag, depending on the type of link.

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::css

div()source public

div( string $class null , string $text null , array $options array() )

Returns a formatted DIV tag for HTML FORMs.

Options

  • escape Whether or not the contents should be html_entity escaped.

Parameters

string $class optional null
CSS class name of the div element.
string $text optional null

String content that will appear inside the div element. If null, only a start tag will be printed

array $options optional array()
Additional HTML attributes of the DIV tag

Returns

string
The formatted DIV element

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::div

docType()source public

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.

Parameters

string $type optional 'html5'
Doctype to use.

Returns

string|null
Doctype string

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::docType

getCrumbList()source public

getCrumbList( array $options array() , 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.

Options

  • 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'

Parameters

array $options optional array()
Array of html attributes to apply to the generated list elements.
string|array|boolean $startText optional false

This will be the first crumb, if false it defaults to first crumb in array. Can also be an array, see HtmlHelper::getCrumbs for details.

Returns

string|null
breadcrumbs html list

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper

getCrumbs()source public

getCrumbs( string $separator '&raquo;' , 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.

Parameters

string $separator optional '&raquo;'
Text to separate crumbs.
string|array|boolean $startText optional false

This will be the first crumb, if false it defaults to first crumb in array. Can also be an array, see above for details.

Returns

string|null
Composed bread crumbs

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper

image()source public

image( string $path , array $options array() )

Creates a formatted IMG element.

This method will set an empty alt attribute if one is not supplied.

Usage:

Create a regular image:

echo $this->Html->image('cake_icon.png', array('alt' => 'CakePHP'));

Create an image link:

echo $this->Html->image('cake_icon.png', array('alt' => 'CakePHP', 'url' => 'http://cakephp.org'));

Options:

  • 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

Parameters

string $path
Path to the image file, relative to the app/webroot/img/ directory.
array $options optional array()
Array of HTML attributes. See above for special options.

Returns

string
completed img tag

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::image
link( string $title , string|array $url null , array $options array() , string $confirmMessage false )

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 HtmlHelper::url() method.

If the $url is empty, $title is used instead.

Options

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

Parameters

string $title
The content to be wrapped by <a> tags.
string|array $url optional null
Cake-relative URL or array of URL parameters, or external URL (starts with http://)
array $options optional array()
Array of options and HTML attributes.
string $confirmMessage optional false

JavaScript confirmation message. This argument is deprecated as of 2.6. Use confirm key in $options instead.

Returns

string
An <a /> element.

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::link

loadConfig()source public

loadConfig( string|array $configFile , string $path null )

Load Html tag configuration.

Loads a file from APP/Config that contains tag data. By default the file is expected to be compatible with PhpReader:

$this->Html->loadConfig('tags.php');

tags.php could look like:

$tags = array(
    'meta' => '<meta%s>'
);

If you wish to store tag definitions in another format you can give an array containing the file name, and reader class name:

$this->Html->loadConfig(array('tags.ini', 'ini'));

Its expected that the tags index will exist from any configuration file that is read. You can also specify the path to read the configuration file from, if APP/Config is not where the file is.

$this->Html->loadConfig('tags.php', APP . 'Lib' . DS);

Configuration files can define the following sections:

  • tags The tags to replace.
  • minimizedAttributes The attributes that are represented like disabled="disabled"
  • docTypes Additional doctypes to use.
  • attributeFormat Format for long attributes e.g. '%s="%s"'
  • minimizedAttributeFormat Format for minimized attributes e.g. '%s="%s"'

Parameters

string|array $configFile
String with the config file (load using PhpReader) or an array with file and reader name
string $path optional null
Path with config file

Returns

mixed
False to error or loaded configs

Throws

ConfigureException

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#changing-the-tags-output-by-htmlhelper

media()source public

media( string|array $path , array $options array() )

Returns an audio/video element

Usage

Using an audio file:

echo $this->Html->media('audio.mp3', array('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', array('text' => 'Fallback text'));

Outputs:

<video src="/files/video.mp4">Fallback text</video>

Using multiple video files:

echo $this->Html->media(
        array('video.mp4', array('src' => 'video.ogv', 'type' => "video/ogg; codecs='theora, vorbis'")),
        array('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>

Options

  • 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 tag
  • pathPrefix Path prefix to use for relative URLs, defaults to 'files/'
  • fullBase If provided the src attribute will get a full address including domain name

Parameters

string|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 src and type

array $options optional array()
Array of HTML attributes, and special options above.

Returns

string
Generated media element

meta()source public

meta( string $type , string|array $url null , array $options array() )

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 $scripts_for_layout:

$this->Html->meta('description', 'A great page', array('inline' => false));

Append the meta tag to custom view block:

$this->Html->meta('description', 'A great page', array('block' => 'metaTags'));

Options

  • inline Whether or not the link element should be output inline. Set to false to have the meta tag included in $scripts_for_layout, and appended to the 'meta' view block.
  • block Choose a custom block to append the meta tag to. Using this option will override the inline option.

Parameters

string $type
The title of the external resource
string|array $url optional null
The address of the external resource or string for content attribute
array $options optional array()

Other attributes for the generated tag. If the type attribute is html, rss, atom, or icon, the mime-type is returned.

Returns

string
A completed <link /> element.

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::meta

nestedList()source public

nestedList( array $list , array $options array() , array $itemOptions array() , string $tag 'ul' )

Build a nested list (UL/OL) out of an associative array.

Parameters

array $list
Set of elements to list
array $options optional array()
Additional HTML attributes of the list (ol/ul) tag or if ul/ol use that as tag
array $itemOptions optional array()
Additional HTML attributes of the list item (LI) tag
string $tag optional 'ul'
Type of list tag to use (ol/ul)

Returns

string
The nested list

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::nestedList

para()source public

para( string $class , string $text , array $options array() )

Returns a formatted P tag.

Options

  • escape Whether or not the contents should be html_entity escaped.

Parameters

string $class
CSS class name of the p element.
string $text
String content that will appear inside the p element.
array $options optional array()
Additional HTML attributes of the P tag

Returns

string
The formatted P element

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::para

script()source public

script( string|array $url , array|boolean $options array() )

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.

Usage

Include one script file:

echo $this->Html->script('styles.js');

Include multiple script files:

echo $this->Html->script(array('one.js', 'two.js'));

Add the script file to the $scripts_for_layout layout var:

$this->Html->script('styles.js', array('inline' => false));

Add the script file to a custom block:

$this->Html->script('styles.js', array('block' => 'bodyScript'));

Options

  • inline Whether script should be output inline or into $scripts_for_layout. When set to false, the script tag will be appended to the 'script' view block as well as $scripts_for_layout.
  • block The name of the block you want the script appended to. Leave undefined to output inline. Using this option will override the inline option.
  • 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 plugin
  • fullBase If true the url will get a full address for the script file.

Parameters

string|array $url
String or array of javascript files to include
array|boolean $options optional array()
Array of options, and html attributes see above. If boolean sets $options['inline'] = value

Returns

mixed

String of <script /> tags or null if $inline is false or if $once is true and the file has been included before.


Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::script

scriptBlock()source public

scriptBlock( string $script , array $options array() )

Wrap $script in a script tag.

Options

  • safe (boolean) Whether or not the $script should be wrapped in <![CDATA[ ]]>
  • inline (boolean) Whether or not the $script should be added to $scripts_for_layout / script block, or output inline. (Deprecated, use block instead)
  • block Which block you want this script block appended to. Defaults to script.

Parameters

string $script
The script to wrap
array $options optional array()

The options to use. Options not listed above will be treated as HTML attributes.

Returns

mixed
string or null depending on the value of $options['block']

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::scriptBlock

scriptEnd()source public

scriptEnd( )

End a Buffered section of JavaScript capturing. Generates a script tag inline or in $scripts_for_layout depending on the settings used when the scriptBlock was started

Returns

mixed
depending on the settings of scriptStart() either a script tag or null

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::scriptEnd

scriptStart()source public

scriptStart( array $options array() )

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.

Options

  • safe Whether the code block should contain a CDATA
  • inline Should the generated script tag be output inline or in $scripts_for_layout

Parameters

array $options optional array()
Options for the code block.

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::scriptStart

style()source public

style( array $data , boolean $oneline true )

Builds CSS style data from an array of CSS properties

Usage:

echo $this->Html->style(array('margin' => '10px', 'padding' => '10px'), true);

// creates
'margin:10px;padding:10px;'

Parameters

array $data
Style data array, keys will be used as property names, values as property values.
boolean $oneline optional true
Whether or not the style block should be displayed on one line.

Returns

string
CSS styling data

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::style

tableCells()source public

tableCells( array $data , array $oddTrOptions null , array $evenTrOptions null , boolean $useCount false , boolean $continueOddEven true )

Returns a formatted string of table rows (TR's with TD's in them).

Parameters

array $data
Array of table data
array $oddTrOptions optional null
HTML options for odd TR elements if true useCount is used
array $evenTrOptions optional null
HTML options for even TR elements
boolean $useCount optional false
adds class "column-$i"
boolean $continueOddEven optional true

If false, will use a non-static $count variable, so that the odd/even count is reset to zero just for that call.

Returns

string
Formatted HTML

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::tableCells

tableHeaders()source public

tableHeaders( array $names , array $trOptions null , array $thOptions null )

Returns a row of formatted and named TABLE headers.

Parameters

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 $trOptions optional null
HTML options for TR elements.
array $thOptions optional null
HTML options for TH elements.

Returns

string
Completed table headers

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::tableHeaders

tag()source public

tag( string $name , string $text null , array $options array() )

Returns a formatted block tag, i.e DIV, SPAN, P.

Options

  • escape Whether or not the contents should be html_entity escaped.

Parameters

string $name
Tag name.
string $text optional null

String content that will appear inside the div element. If null, only a start tag will be printed

array $options optional array()
Additional HTML attributes of the DIV tag, see above.

Returns

string
The formatted tag element

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::tag

useTag()source public

useTag( string $tag )

Returns a formatted existent block of $tags

Parameters

string $tag
Tag name

Returns

string
Formatted block

Link

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::useTag

Methods inherited from Helper

__call()source public

__call( string $method , array $params )

Provide non fatal errors on missing method calls.

Parameters

string $method
Method to invoke
array $params
Array of params for the method.

__get()source public

__get( string $name )

Lazy loads helpers. Provides access to deprecated request properties as well.

Deprecated

3.0.0 Accessing request properties through this method is deprecated and will be removed in 3.0.

Parameters

string $name
Name of the property being accessed.

Returns

mixed
Helper or property found at $name

__set()source public

__set( string $name , mixed $value )

Provides backwards compatibility access for setting values to the request object.

Deprecated

3.0.0 This method will be removed in 3.0

Parameters

string $name
Name of the property being accessed.
mixed $value
Value to set.

_clean()source protected

_clean( )

Removes harmful content from output

_confirm()source protected

_confirm( string $message , string $okCode , string $cancelCode '' , array $options array() )

Returns a string to be used as onclick handler for confirm dialogs.

Parameters

string $message
Message to be displayed
string $okCode
Code to be executed after user chose 'OK'
string $cancelCode optional ''
Code to be executed after user chose 'Cancel', also executed when okCode doesn't return
array $options optional array()
Array of options

Returns

string
onclick JS code

_encodeUrl()source protected

_encodeUrl( string $url )

Encodes a URL for use in HTML attributes.

Parameters

string $url
The URL to encode.

Returns

string
The URL encoded for both URL & HTML contexts.

_formatAttribute()source protected

_formatAttribute( string $key , string $value , boolean $escape true )

Formats an individual attribute, and returns the string value of the composed attribute. Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'

Deprecated

3.0.0 This method will be moved to HtmlHelper in 3.0

Parameters

string $key
The name of the attribute to create
string $value
The value of the attribute to create.
boolean $escape optional true
Define if the value must be escaped

Returns

string
The composed attribute.

_initInputField()source protected

_initInputField( string $field , array $options array() )

Sets the defaults for an input tag. Will set the name, value, and id attributes for an array of html attributes.

Parameters

string $field
The field name to initialize.
array $options optional array()
Array of options to use while initializing an input field.

Returns

array
Array options for the form input.

_name()source protected

_name( array|string $options array() , string $field null , string $key 'name' )

Gets the input field name for the current tag. Creates input name attributes using CakePHP's data[Model][field] formatting.

Parameters

array|string $options optional array()

If an array, should be an array of attributes that $key needs to be added to. If a string or null, will be used as the View entity.

string $field optional null
Field name.
string $key optional 'name'
The name of the attribute to be set, defaults to 'name'

Returns

mixed

If an array was given for $options, an array with $key set will be returned. If a string was supplied a string will be returned.


_parseAttributes()source protected

_parseAttributes( array $options , array $exclude null , string $insertBefore ' ' , string $insertAfter null )

Returns a space-delimited string with items of the $options array. If a key of $options array happens to be one of those listed in Helper::$_minimizedAttributes

And its value is one of:

  • '1' (string)
  • 1 (integer)
  • true (boolean)
  • 'true' (string)

Then the value will be reset to be identical with key's name. If the value is not one of these 3, the parameter is not output.

'escape' is a special option in that it controls the conversion of attributes to their html-entity encoded equivalents. Set to false to disable html-encoding.

If value for any option key is set to null or false, that option will be excluded from output.

Deprecated

3.0.0 This method will be moved to HtmlHelper in 3.0

Parameters

array $options
Array of options.
array $exclude optional null
Array of options to be excluded, the options here will not be part of the return.
string $insertBefore optional ' '
String to be inserted before options.
string $insertAfter optional null
String to be inserted after options.

Returns

string
Composed attributes.

_reset()source protected

_reset( )

Resets the vars used by Helper::clean() to null

_selectedArray()source protected

_selectedArray( string|array $data , string $key 'id' )

Transforms a recordset from a hasAndBelongsToMany association to a list of selected options for a multiple select element

Parameters

string|array $data
Data array or model name.
string $key optional 'id'
Field name.

Returns

array

addClass()source public

addClass( array $options array() , string $class null , string $key 'class' )

Adds the given class to the element options

Parameters

array $options optional array()
Array options/attributes to add a class to
string $class optional null
The class name being added.
string $key optional 'class'
the key to use for class.

Returns

array
Array of options with $key set.

afterLayout()source public

afterLayout( string $layoutFile )

After layout callback. afterLayout is called after the layout has rendered.

Overridden in subclasses.

Parameters

string $layoutFile
The layout file that was rendered.

afterRender()source public

afterRender( string $viewFile )

After render callback. afterRender is called after the view file is rendered but before the layout has been rendered.

Overridden in subclasses.

Parameters

string $viewFile
The view file that was rendered.

afterRenderFile()source public

afterRenderFile( string $viewFile , string $content )

After render file callback. Called after any view fragment is rendered.

Overridden in subclasses.

Parameters

string $viewFile
The file just be rendered.
string $content
The content that was rendered.

assetTimestamp()source public

assetTimestamp( string $path )

Adds a timestamp to a file based resource based on the value of Asset.timestamp in Configure. If Asset.timestamp is true and debug > 0, or Asset.timestamp === 'force' a timestamp will be added.

Parameters

string $path
The file path to timestamp, the path must be inside WWW_ROOT

Returns

string
Path with a timestamp added, or not.

assetUrl()source public

assetUrl( string|array $path , array $options array() )

Generate URL for given asset file. Depending on options passed provides full URL with domain name. Also calls Helper::assetTimestamp() to add timestamp to local files

Parameters

string|array $path
Path string or URL array
array $options optional array()

Options array. Possible keys: fullBase Return full URL with domain name pathPrefix Path prefix for relative URLs ext Asset extension to append plugin False value will prevent parsing path as a plugin

Returns

string
Generated URL

beforeLayout()source public

beforeLayout( string $layoutFile )

Before layout callback. beforeLayout is called before the layout is rendered.

Overridden in subclasses.

Parameters

string $layoutFile
The layout about to be rendered.

beforeRender()source public

beforeRender( string $viewFile )

Before render callback. beforeRender is called before the view file is rendered.

Overridden in subclasses.

Parameters

string $viewFile
The view file that is going to be rendered

beforeRenderFile()source public

beforeRenderFile( string $viewFile )

Before render file callback. Called before any view fragment is rendered.

Overridden in subclasses.

Parameters

string $viewFile
The file about to be rendered.

clean()source public

clean( string|array $output )

Used to remove harmful tags from content. Removes a number of well known XSS attacks from content. However, is not guaranteed to remove all possibilities. Escaping content is the best way to prevent all possible attacks.

Deprecated

3.0.0 This method will be removed in 3.0

Parameters

string|array $output
Either an array of strings to clean or a single string to clean.

Returns

string|array|null
Cleaned content for output

domId()source public

domId( array|string $options null , string $id 'id' )

Generates a DOM ID for the selected element, if one is not set. Uses the current View::entity() settings to generate a CamelCased id attribute.

Parameters

array|string $options optional null

Either an array of html attributes to add $id into, or a string with a view entity path to get a domId for.

string $id optional 'id'
The name of the 'id' attribute.

Returns

mixed

If $options was an array, an array will be returned with $id set. If a string was supplied, a string will be returned.


entity()source public

entity( )

Returns the entity reference of the current context as an array of identity parts

Returns

array
An array containing the identity elements of an entity

field()source public

field( )

Gets the currently-used model field of the rendering context. Strips off field suffixes such as year, month, day, hour, min, meridian when the current entity is longer than 2 elements.

Returns

string

model()source public

model( )

Gets the currently-used model of the rendering context.

Returns

string

output()source public

output( string $str )

Returns a string generated by a helper method

This method can be overridden in subclasses to do generalized output post-processing

Deprecated

3.0.0 This method will be removed in future versions.

Parameters

string $str
String to be output.

Returns

string

setEntity()source public

setEntity( string $entity , boolean $setScope false )

Sets this helper's model and field properties to the dot-separated value-pair in $entity.

Parameters

string $entity
A field name, like "ModelName.fieldName" or "ModelName.ID.fieldName"
boolean $setScope optional false
Sets the view scope to the model specified in $tagValue

url()source public

url( string|array $url null , boolean $full false )

Finds URL for specified action.

Returns a URL pointing at the provided parameters.

Parameters

string|array $url optional null

Either a relative string url like /products/view/23 or an array of URL parameters. Using an array for URLs will allow you to leverage the reverse routing features of CakePHP.

boolean $full optional false
If true, the full base URL will be prepended to the result

Returns

string
Full translated URL with base path.

Link

http://book.cakephp.org/2.0/en/views/helpers.html

value()source public

value( array|string $options array() , string $field null , string $key 'value' )

Gets the data for the current tag

Parameters

array|string $options optional array()

If an array, should be an array of attributes that $key needs to be added to. If a string or null, will be used as the View entity.

string $field optional null
Field name.
string $key optional 'value'
The name of the attribute to be set, defaults to 'value'

Returns

mixed

If an array was given for $options, an array with $key set will be returned. If a string was supplied a string will be returned.


webroot()source public

webroot( string $file )

Checks if a file exists when theme is used, if no file is found default location is returned

Parameters

string $file
The file to create a webroot path to.

Returns

string
Web accessible path to file.

Methods inherited from Object

_mergeVars()source protected

_mergeVars( array $properties , string $class , boolean $normalize true )

Merges this objects $property with the property in $class' definition. This classes value for the property will be merged on top of $class'

This provides some of the DRY magic CakePHP provides. If you want to shut it off, redefine this method as an empty function.

Parameters

array $properties
The name of the properties to merge.
string $class
The class to merge the property with.
boolean $normalize optional true
Set to true to run the properties through Hash::normalize() before merging.

_set()source protected

_set( array $properties array() )

Allows setting of multiple properties of the object in a single line of code. Will only set properties that are part of a class declaration.

Parameters

array $properties optional array()
An associative array containing properties and corresponding values.

_stop()source protected

_stop( integer|string $status 0 )

Stop execution of the current script. Wraps exit() making testing easier.

Parameters

integer|string $status optional 0
see http://php.net/exit for values

dispatchMethod()source public

dispatchMethod( string $method , array $params array() )

Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array

Parameters

string $method
Name of the method to call
array $params optional array()
Parameter list to use when calling $method

Returns

mixed
Returns the result of the method call

log()source public

log( string $msg , integer $type LOG_ERR , null|string|array $scope null )

Convenience method to write a message to CakeLog. See CakeLog::write() for more information on writing to logs.

Parameters

string $msg
Log message
integer $type optional LOG_ERR
Error type constant. Defined in app/Config/core.php.
null|string|array $scope optional null

The scope(s) a log message is being created in. See CakeLog::config() for more information on logging scopes.

Returns

boolean
Success of log write

requestAction()source public

requestAction( string|array $url , array $extra array() )

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

Passing POST and GET data

POST and GET data can be simulated in requestAction. Use $extra['url'] for GET data. The $extra['data'] parameter allows POST data simulation.

Parameters

string|array $url

String or array-based URL. Unlike other URL arrays in CakePHP, this URL will not automatically handle passed and named arguments in the $url parameter.

array $extra optional array()

if array includes the key "return" it sets the AutoRender to true. Can also be used to submit GET/POST data, and named/passed arguments.

Returns

mixed

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


toString()source public

toString( )

Object-to-string conversion. Each class can override this method as necessary.

Returns

string
The name of this class

Properties detail

$_crumbssource

protected array

Breadcrumbs.

array()

$_docTypessource

protected array

Document type definitions

array(
    'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
    'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
    'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
    'html5' => '<!DOCTYPE html>',
    'xhtml-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
    'xhtml-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
    'xhtml-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
    'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
)

$_includedAssetssource

protected array

Names of script & css files that have been included once

array()

$_scriptBlockOptionssource

protected array

Options for the currently opened script block buffer if any.

array()

$_tagssource

protected array

html tags used by this helper.

array(
    'meta' => '<meta%s/>',
    'metalink' => '<link href="%s"%s/>',
    'link' => '<a href="%s"%s>%s</a>',
    'mailto' => '<a href="mailto:%s"%s>%s</a>',
    'form' => '<form action="%s"%s>',
    'formwithoutaction' => '<form%s>',
    'formend' => '</form>',
    'input' => '<input name="%s"%s/>',
    'textarea' => '<textarea name="%s"%s>%s</textarea>',
    'hidden' => '<input type="hidden" name="%s"%s/>',
    'checkbox' => '<input type="checkbox" name="%s"%s/>',
    'checkboxmultiple' => '<input type="checkbox" name="%s[]"%s />',
    'radio' => '<input type="radio" name="%s" id="%s"%s />%s',
    'selectstart' => '<select name="%s"%s>',
    'selectmultiplestart' => '<select name="%s[]"%s>',
    'selectempty' => '<option value=""%s>&nbsp;</option>',
    'selectoption' => '<option value="%s"%s>%s</option>',
    'selectend' => '</select>',
    'optiongroup' => '<optgroup label="%s"%s>',
    'optiongroupend' => '</optgroup>',
    'checkboxmultiplestart' => '',
    'checkboxmultipleend' => '',
    'password' => '<input type="password" name="%s"%s/>',
    'file' => '<input type="file" name="%s"%s/>',
    'file_no_model' => '<input type="file" name="%s"%s/>',
    'submit' => '<input%s/>',
    'submitimage' => '<input type="image" src="%s"%s/>',
    'button' => '<button%s>%s</button>',
    'image' => '<img src="%s"%s/>',
    'tableheader' => '<th%s>%s</th>',
    'tableheaderrow' => '<tr%s>%s</tr>',
    'tablecell' => '<td%s>%s</td>',
    'tablerow' => '<tr%s>%s</tr>',
    'block' => '<div%s>%s</div>',
    'blockstart' => '<div%s>',
    'blockend' => '</div>',
    'hiddenblock' => '<div style="display:none;">%s</div>',
    'tag' => '<%s%s>%s</%s>',
    'tagstart' => '<%s%s>',
    'tagend' => '</%s>',
    'tagselfclosing' => '<%s%s/>',
    'para' => '<p%s>%s</p>',
    'parastart' => '<p%s>',
    'label' => '<label for="%s"%s>%s</label>',
    'fieldset' => '<fieldset%s>%s</fieldset>',
    'fieldsetstart' => '<fieldset><legend>%s</legend>',
    'fieldsetend' => '</fieldset>',
    'legend' => '<legend>%s</legend>',
    'css' => '<link rel="%s" type="text/css" href="%s"%s/>',
    'style' => '<style type="text/css"%s>%s</style>',
    'charset' => '<meta http-equiv="Content-Type" content="text/html; charset=%s" />',
    'ul' => '<ul%s>%s</ul>',
    'ol' => '<ol%s>%s</ol>',
    'li' => '<li%s>%s</li>',
    'error' => '<div%s>%s</div>',
    'javascriptblock' => '<script%s>%s</script>',
    'javascriptstart' => '<script>',
    'javascriptlink' => '<script type="text/javascript" src="%s"%s></script>',
    'javascriptend' => '</script>'
)

$responsesource

public CakeResponse

Reference to the Response object

© 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/2.8/class-HtmlHelper.html