KMP PHP API Reference

HtmlHelper extends HtmlHelper
in package
uses ClassTrait, EasyIconTrait

Html Helper class for easy use of HTML widgets.

HtmlHelper encloses all methods needed while working with HTML pages.

Tags
link
http://book.cakephp.org/3.0/en/views/helpers/html.html

Table of Contents

Properties

$easyIcon  : bool
Set to false to disable easy icon processing.
$Url  : UrlHelper
$_defaultConfig  : array<string|int, mixed>
Default config for the helper.

Methods

addClass()  : array<string|int, mixed>
Adds the given class to the element options.
alert()  : string
Create a Twitter Bootstrap style alert block, containing text.
badge()  : string
Create a Twitter Bootstrap badge.
dropdown()  : string
Create & return a twitter bootstrap dropdown menu.
icon()  : string
Create an icon using the template `icon`.
link()  : string
{@inheritDoc}
progress()  : string
Create a Twitter Bootstrap style progress bar.
tooltip()  : string
Create a Twitter Bootstrap style tooltip.
_addButtonClasses()  : array<string|int, mixed>
Add classes to options according to the default values of bootstrap-type and bootstrap-size for button (see configuration).
_easyIconOption()  : array<string|int, mixed>
Remove the `easyIcon` option from the given array and return it together with the array.
_injectIcon()  : string
Inject icon into the given string.
_isAssociativeArray()  : bool
Check weither the specified array is associative or not.
_makeIcon()  : string
Try to convert the specified string to a bootstrap icon. The string is converted if it matches a format `i:icon-name` (leading and trailing spaces or ignored) and if easy-icon is activated.

Properties

$easyIcon

Set to false to disable easy icon processing.

public bool $easyIcon = true

$_defaultConfig

Default config for the helper.

protected array<string|int, mixed> $_defaultConfig = ["templates" => [ "meta" => "<meta{{attrs}}/>", "metalink" => '<link href="{{url}}"{{attrs}}/>', "link" => '<a href="{{url}}"{{attrs}}>{{content}}</a>', "mailto" => '<a href="mailto:{{url}}"{{attrs}}>{{content}}</a>', "image" => '<img src="{{url}}"{{attrs}}/>', "tableheader" => "<th{{attrs}}>{{content}}</th>", "tableheaderrow" => "<tr{{attrs}}>{{content}}</tr>", "tablecell" => "<td{{attrs}}>{{content}}</td>", "tablerow" => "<tr{{attrs}}>{{content}}</tr>", "block" => "<div{{attrs}}>{{content}}</div>", "blockstart" => "<div{{attrs}}>", "blockend" => "</div>", "tag" => "<{{tag}}{{attrs}}>{{content}}</{{tag}}>", "tagstart" => "<{{tag}}{{attrs}}>", "tagend" => "</{{tag}}>", "tagselfclosing" => "<{{tag}}{{attrs}}/>", "para" => "<p{{attrs}}>{{content}}</p>", "parastart" => "<p{{attrs}}>", "css" => '<link rel="{{rel}}" href="{{url}}"{{attrs}}/>', "style" => "<style{{attrs}}>{{content}}</style>", "charset" => '<meta charset="{{charset}}"/>', "ul" => "<ul{{attrs}}>{{content}}</ul>", "ol" => "<ol{{attrs}}>{{content}}</ol>", "li" => "<li{{attrs}}>{{content}}</li>", "javascriptblock" => "<script{{attrs}}>{{content}}</script>", "javascriptstart" => "<script>", "javascriptlink" => '<script src="{{url}}"{{attrs}}></script>', "javascriptend" => "</script>", // New templates for Bootstrap "icon" => '<i aria-hidden="true" class="fa fa-{{type}}{{attrs.class}}"{{attrs}}></i>', "badge" => '<span class="badge badge-{{type}}{{attrs.class}}"{{attrs}}>{{content}}</span>', "alert" => '<div class="alert alert-{{type}}{{attrs.class}}" role="alert"{{attrs}}>{{close}}{{content}}</div>', "alertCloseButton" => '<button type="button" class="close{{attrs.class}}" data-dismiss="alert" aria-label="{{label}}"{{attrs}}>{{content}}</button>', "alertCloseContent" => '<span aria-hidden="true">&times;</span>', "tooltip" => '<{{tag}} data-toggle="{{toggle}}" data-placement="{{placement}}" title="{{tooltip}}"{{attrs}}>{{content}}</{{tag}}>', "progressBar" => '<div class="progress-bar bg-{{type}}{{attrs.class}}" role="progressbar" aria-valuenow="{{width}}" aria-valuemin="{{min}}" aria-valuemax="{{max}}" style="width: {{width}}%;"{{attrs}}>{{inner}}</div>', "progressBarInner" => '<span class="sr-only">{{width}}%</span>', "progressBarContainer" => '<div class="progress{{attrs.class}}"{{attrs}}>{{content}}</div>', "dropdownMenu" => '<div class="dropdown-menu{{attrs.class}}"{{attrs}}>{{content}}</div>', "dropdownMenuItem" => '<a href="{{url}}" class="dropdown-item{{attrs.class}}"{{attrs}}>{{content}}</a>', "dropdownMenuHeader" => '<h6 class="dropdown-header{{attrs.class}}"{{attrs}}>{{content}}</h6>', "dropdownMenuDivider" => '<div role="separator" class="dropdown-divider{{attrs.class}}"{{attrs}}></div>', "confirmJs" => "{{confirm}}", ], "templateClass" => "Bootstrap\\View\\EnhancedStringTemplate", "tooltip" => ["tag" => "span", "placement" => "right", "toggle" => "tooltip"], "badge" => ["type" => "default"], "alert" => ["type" => "warning", "close" => true], "progress" => ["type" => "primary"]]

Options:

  • alert Default options for alert.
  • label Default options for labels.
  • progress Default options for progress bar.
  • tooltip Default options for tooltips.
  • See CakePHP documentation for extra configuration options.

Methods

addClass()

Adds the given class to the element options.

public addClass([array<string|int, mixed> $options = [] ][, string|array<string|int, mixed> $class = null ][, string $key = "class" ]) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed> = []

Array of options/attributes to add a class to.

$class : string|array<string|int, mixed> = null

The class names to be added.

$key : string = "class"

The key to use for class (default to 'class').

Return values
array<string|int, mixed>

Array of options with $key set or modified.

alert()

Create a Twitter Bootstrap style alert block, containing text.

public alert(string $text[, string|array<string|int, mixed>|null $type = null ][, array<string|int, mixed> $options = [] ]) : string

The second parameter may either be $type or $options (in this case, the third parameter is not used, and the alert type can be specified in the $options array).

Options

  • close Dismissible alert. See configuration for default.
  • type The type of the alert. See configuration for default.
  • templateVars Provide template variables for the alert template.
  • Other attributes will be assigned to the wrapper element.
Parameters
$text : string

The alert text.

$type : string|array<string|int, mixed>|null = null

The type of the alert.

$options : array<string|int, mixed> = []

Array of options. See above.

Return values
string

A HTML bootstrap alert element.

badge()

Create a Twitter Bootstrap badge.

public badge(string $text[, string|array<string|int, mixed> $type = null ][, array<string|int, mixed> $options = [] ]) : string

Options

  • templateVars Provide template variables for the badge template.
  • Other attributes will be assigned to the wrapper element.
Parameters
$text : string

The badge text.

$type : string|array<string|int, mixed> = null

The badge type (default, primary, secondary, success, warning, info, danger) or the array of options (see $options).

$options : array<string|int, mixed> = []

Array of options. See above. Default values are retrieved from the configuration.

Return values
string

dropdown()

Create & return a twitter bootstrap dropdown menu.

public dropdown([array<string|int, mixed> $menu = [] ][, array<string|int, mixed> $options = [] ]) : string
[
  // Divider
  'divider',
  ['divider'],
  ['divider' => true]
  // Header
  ['header', $title],
  ['header' => $title],
  ['header' => ['title' => $title, ...]] // Remaining options
  // Link item
  [$name, $url, ...] // Remaining options
  ['link', $name, $url, ...] // Remaining options
  ['item' => ['title' => $title, 'url' => $url, ...]] // Remaining options
  // Non-link item
  ['item' => ['title' => $title, ...]] // Remaining options
  'My Item'
]
Parameters
$menu : array<string|int, mixed> = []

HTML tags corresponding to menu options (which will be wrapped into <li> tag). To add separator, pass 'divider'.

$options : array<string|int, mixed> = []

Attributes for the wrapper (change it with tag).

Return values
string

icon()

Create an icon using the template `icon`.

public icon(string $icon[, array<string|int, mixed> $options = [] ]) : string

Options

  • templateVars Provide template variables for the icon template.
  • Other attributes will be assigned to the wrapper element.
Parameters
$icon : string

Name of the icon.

$options : array<string|int, mixed> = []

Array of options. See above.

Return values
string

The HTML icon.

{@inheritDoc}

public link(mixed $title[, mixed $url = null ][, array<string|int, mixed> $options = [] ]) : string
Parameters
$title : mixed
$url : mixed = null
$options : array<string|int, mixed> = []
Return values
string

progress()

Create a Twitter Bootstrap style progress bar.

public progress(int|array<string|int, mixed> $widths[, array<string|int, mixed> $options = [] ]) : string

Bar options:

  • active If true the progress bar will be active. Default is false.
  • max Maximum value for the progress bar. Default is 100.
  • min Minimum value for the progress bar. Default is 0.
  • striped If true the progress bar will be striped. Default is false.
  • type A string containing the type of the progress bar (primary, info, danger, success, warning). Default to 'primary'.
  • templateVars Provide template variables for the progressBar template.
  • Other attributes will be assigned to the progress bar element.
Parameters
$widths : int|array<string|int, mixed>

Progress width

  • int The width (in %) of the bar.
  • array An array of bars, with, for each bar, the following fields:
    • width required The width of the bar.
    • Other options possible (see above).
$options : array<string|int, mixed> = []

Array of options. See above.

Return values
string

The HTML bootstrap progress bar.

tooltip()

Create a Twitter Bootstrap style tooltip.

public tooltip(string $text, string $tooltip[, array<string|int, mixed> $options = [] ]) : string

Options

  • toggle The 'data-toggle' HTML attribute.
  • placement The data-placement HTML attribute.
  • tag The tag to use.
  • templateVars Provide template variables for the tooltip template.
  • Other attributes will be assigned to the wrapper element.
Parameters
$text : string

The HTML tag inner text.

$tooltip : string

The tooltip text.

$options : array<string|int, mixed> = []

An array of options. See above. Default values are retrieved from the configuration.

Return values
string

The text wrapped in the specified HTML tag with a tooltip.

_addButtonClasses()

Add classes to options according to the default values of bootstrap-type and bootstrap-size for button (see configuration).

protected _addButtonClasses(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>

The initial options with btype and/or size, block values.

Return values
array<string|int, mixed>

The new options with class values (btn, and btn-* according to initial options).

_easyIconOption()

Remove the `easyIcon` option from the given array and return it together with the array.

protected _easyIconOption(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>

Array of options from which the easy-icon option should be extracted.

Return values
array<string|int, mixed>

An array containing the options and the easy-icon option.

_injectIcon()

Inject icon into the given string.

protected _injectIcon(string $title, bool $easyIcon) : string
Parameters
$title : string

Input string where icon should be injected following the easy-icon process.

$easyIcon : bool

Boolean indicating if the easy-icon process should be applied.

Return values
string

_isAssociativeArray()

Check weither the specified array is associative or not.

protected _isAssociativeArray(array<string|int, mixed> $array) : bool
Parameters
$array : array<string|int, mixed>

The array to check.

Return values
bool

true if the array is associative, false otherwize.

_makeIcon()

Try to convert the specified string to a bootstrap icon. The string is converted if it matches a format `i:icon-name` (leading and trailing spaces or ignored) and if easy-icon is activated.

protected _makeIcon(string $text[, bool &$converted = false ]) : string

Note: This function will currently fail if the Html helper associated with the view is not BootstrapHtmlHelper.

Parameters
$text : string

The string to convert.

$converted : bool = false

If specified, will contains true if the text was converted, false otherwize.

Return values
string

The text after conversion.


        
On this page

Search results