CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.6 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.6
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • CacheHelper
  • FormHelper
  • HtmlHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • MootoolsEngineHelper
  • NumberHelper
  • PaginatorHelper
  • PrototypeEngineHelper
  • RssHelper
  • SessionHelper
  • TextHelper
  • TimeHelper

Class HtmlHelper

Html Helper class for easy use of HTML widgets.

HtmlHelper encloses all methods needed while working with HTML pages.

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

  • $_crumbs protected
    array
    Breadcrumbs.
  • $_docTypes protected
    array
    Document type definitions
  • $_includedAssets protected
    array
    Names of script & css files that have been included once
  • $_scriptBlockOptions protected
    array
    Options for the currently opened script block buffer if any.
  • $_tags protected
    array
    html tags used by this helper.
  • $response public
    CakeResponse
    Reference to the Response object

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.
  • getCrumbList() public
    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).
  • tableHeaders() public
    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() 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.

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

$this
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() 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() 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 or