Class HtmlHelper
Html Helper class for easy use of HTML widgets.
HtmlHelper encloses all methods needed while working with HTML pages.
- AppHelper
- HtmlHelper
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: The MIT License
Location: view/helpers/html.php
Properties summary
-
$__docTypes
publicarray
Document type definitions -
$_crumbs
publicarray
Breadcrumbs. -
$action
publicstring
Current action. -
$base
publicstring
Base URL -
$data
publicarray
Enter description here... -
$here
publicstring
URL to current action. -
$params
publicarray
Parameter array. -
$tags
publicarray
html tags used by this helper.
Method Summary
-
__nestedListItem() public
Internal function to build a nested list (UL/OL) out of an associative array. -
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. -
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. -
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. -
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). -
tableHeaders() public
Returns a row of formatted and named TABLE headers. -
tag() public
Returns a formatted block tag, i.e DIV, SPAN, P.
Method Detail
__nestedListItem() public ¶
__nestedListItem( array $items , array $attributes , array $itemAttributes , string $tag )
Internal function to build a nested list (UL/OL) out of an associative array.
Parameters
- array $items
- $list Set of elements to list
- array $attributes
- Additional HTML attributes of the list (ol/ul) tag
- array $itemAttributes
- Additional HTML attributes of the list item (LI) tag
- string $tag
- Type of list tag to use (ol/ul)
Returns
The nested list element
See
addCrumb() public ¶
addCrumb( string $name , string $link = null , mixed $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)
- mixed $options optional null
- Link attributes e.g. array('id'=>'selected')
charset() 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. Example: "utf-8".
Returns
A meta tag containing the specified character set.
css() public ¶
css( mixed $path , string $rel = null , array $htmlAttributes = array() , boolean $inline = true )
Creates a link element for CSS stylesheets.
Parameters
- mixed $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.- string $rel optional null
- Rel attribute. Defaults to "stylesheet". If equal to 'import' the stylesheet will be imported.
- array $htmlAttributes optional array()
- Array of HTML attributes.
- boolean $inline optional true
- If set to false, the generated tag appears in the head tag of the layout.
Returns
CSS or tag, depending on the type of link.
div() public ¶
div( string $class = null , string $text = null , array $attributes = array() , boolean $escape = false )
Returns a formatted DIV tag for HTML FORMs.
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 $attributes optional array()
- Additional HTML attributes of the DIV tag
- boolean $escape optional false
- If true, $text will be HTML-escaped
Returns
The formatted DIV element
docType() public ¶
docType( string $type = 'xhtml-strict' )
Returns a doctype string.
Possible doctypes: + html4-strict: HTML4 Strict. + html4-trans: HTML4 Transitional. + html4-frame: HTML4 Frameset. + xhtml-strict: XHTML1 Strict. + xhtml-trans: XHTML1 Transitional. + xhtml-frame: XHTML1 Frameset. + xhtml11: XHTML1.1.
Parameters
- string $type optional 'xhtml-strict'
- Doctype to use.
Returns
Doctype.
getCrumbs() public ¶
getCrumbs( string $separator = '»' , string $startText = false )
Returns the breadcrumb trail as a sequence of »-separated links.
Parameters
- string $separator optional '»'
- Text to separate crumbs.
- string $startText optional false
- This will be the first crumb, if false it defaults to first crumb in array
Returns
image() public ¶
image( string $path , array $options = array() )
Creates a formatted IMG element.
Parameters
- string $path
- Path to the image file, relative to the app/webroot/img/ directory.
- array $options optional array()
- Array of HTML attributes.
Returns
link() public ¶
link( string $title , mixed $url = null , array $htmlAttributes = array() , string $confirmMessage = false , boolean $escapeTitle = true )
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.
Parameters
- string $title
- The content to be wrapped by tags.
- mixed $url optional null
- Cake-relative URL or array of URL parameters, or external URL (starts with http://)
- array $htmlAttributes optional array()
- Array of HTML attributes.
- string $confirmMessage optional false
- JavaScript confirmation message.
- boolean $escapeTitle optional true
- Whether or not $title should be HTML escaped.
Returns
meta() public ¶
meta( string $type , mixed $url = null , array $attributes = array() , boolean $inline = true )
Creates a link to an external resource and handles basic meta tags
Parameters
- string $type
- The title of the external resource
- mixed $url optional null
- The address of the external resource or string for content attribute
- array $attributes optional array()
- Other attributes for the generated tag. If the type attribute is html, rss, atom, or icon, the mime-type is returned.
- boolean $inline optional true
- If set to false, the generated tag appears in the head tag of the layout.
Returns
nestedList() public ¶
nestedList( array $list , array $attributes = array() , array $itemAttributes = array() , string $tag = 'ul' )
Build a nested list (UL/OL) out of an associative array.
Parameters
- array $list
- Set of elements to list
- array $attributes optional array()
- Additional HTML attributes of the list (ol/ul) tag or if ul/ol use that as tag
- array $itemAttributes optional array()
- Additional HTML attributes of the list item (LI) tag
- string $tag optional 'ul'
- Type of list tag to use (ol/ul)
Returns
The nested list
para() public ¶
para( string $class , string $text , array $attributes = array() , boolean $escape = false )
Returns a formatted P tag.
Parameters
- string $class
- CSS class name of the p element.
- string $text
- String content that will appear inside the p element.
- array $attributes optional array()
- Additional HTML attributes of the P tag
- boolean $escape optional false
- If true, $text will be HTML-escaped
Returns
The formatted P element
style() public ¶
style( array $data , boolean $inline = true )
Builds CSS style data from an array of CSS properties
Parameters
- array $data
- Style data array
- boolean $inline optional true
- Whether or not the style block should be displayed inline
Returns
CSS styling data
tableCells() 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
Formatted HTML
tableHeaders() 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.
- array $trOptions optional null
- HTML options for TR elements.
- array $thOptions optional null
- HTML options for TH elements.
Returns
tag() public ¶
tag( string $name , string $text = null , array $attributes = array() , boolean $escape = false )
Returns a formatted block tag, i.e DIV, SPAN, P.
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 $attributes optional array()
- Additional HTML attributes of the DIV tag
- boolean $escape optional false
- If true, $text will be HTML-escaped
Returns
The formatted tag element
Properties detail
$__docTypes ¶
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">', '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">' )
$tags ¶
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 %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> </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 type="submit" %s/>', 'submitimage' => '<input type="image" src="%s" %s/>', 'button' => '<input type="%s" %s/>', '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>', 'tag' => '<%s%s>%s</%s>', 'tagstart' => '<%s%s>', 'tagend' => '</%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>' )