Skip to content

Phalcon Tag

Updated View as Markdown

Tag

ClassSource on GitHub

Phalcon\Tag is designed to simplify building of HTML tags. It provides a set of helpers to generate HTML in a dynamic way. This component is a class that you can extend to add more helpers.

  • Phalcon\Tag

Uses Phalcon\Di\Di · Phalcon\Di\DiInterface · Phalcon\Html\Escaper\EscaperInterface · Phalcon\Html\Link\Link · Phalcon\Html\Link\Serializer\Header · Phalcon\Http\ResponseInterface · Phalcon\Mvc\Url · Phalcon\Mvc\Url\UrlInterface · Phalcon\Support\Helper\Str\Friendly · Phalcon\Tag\Exception · Phalcon\Tag\Select · Stringable

Method Summary

publicvoidappendTitle(array|string $title)

Appends a text to current document title

publicstringcheckField(array|string $parameters)

Builds an HTML input[type=“check”] tag

publicstringcolorField(array|string $parameters)

Builds an HTML input[type=“color”] tag

publicstringdateField(array|string $parameters)

Builds an HTML input[type=“date”] tag

publicstringdateTimeField(array|string $parameters)

Builds an HTML input[type=“datetime”] tag

publicstringdateTimeLocalField(array|string $parameters)

Builds an HTML input[type=“datetime-local”] tag

publicvoiddisplayTo(string $id,mixed $value)

Alias of Phalcon\Tag::setDefault()

publicstringemailField(array|string $parameters)

Builds an HTML input[type=“email”] tag

publicstringendForm()

Builds an HTML close FORM tag

publicstringfileField(array|string $parameters)

Builds an HTML input[type=“file”] tag

publicstringformLegacy(array|string $parameters)

Builds an HTML FORM tag

publicstringfriendlyTitle(string $text,string $separator = "-",bool $lowercase = true,array|string $replace = [])

Converts texts into URL-friendly titles

publicDiInterfacegetDI()

Internally gets the request dispatcher

publicstringgetDocType()

Get the document type declaration of content

publicEscaperInterface|nullgetEscaper(array $parameters)

Obtains the ‘escaper’ service if required

publicEscaperInterfacegetEscaperService()

Returns an Escaper service from the default DI

publicstringgetTitle(bool $prepend = true,bool $append = true)

Gets the current document title. The title will be automatically escaped.

publicstringgetTitleSeparator()

Gets the current document title separator

publicUrlInterfacegetUrlService()

Returns a URL service from the default DI

publicmixedgetValue(int|string $name,array $parameters = [])

Every helper calls this function to check whether a component has a

publicboolhasValue(int|string $name)

Check if a helper has a default value set using Phalcon\Tag::setDefault()

publicstringhiddenField(array|string $parameters)

Builds a HTML input[type=“hidden”] tag

publicstringimage(array|string $parameters = [],bool $local = true)

Builds HTML IMG tags

publicstringimageInput(array|string $parameters)

Builds an HTML input[type=“image”] tag

publicstringjavascriptInclude(array|string $parameters = [],bool $local = true)

Builds a SCRIPT[type=“javascript”] tag

publicstringlinkTo(array|string $parameters,string|null $text = null,bool $local = true)

Builds an HTML A tag using framework conventions

publicstringmonthField(array|string $parameters)

Builds an HTML input[type=“month”] tag

publicstringnumericField(array|string $parameters)

Builds an HTML input[type=“number”] tag

publicstringpasswordField(array|string $parameters)

Builds a HTML input[type=“password”] tag

publicstringpreload(array|string $parameters)

Parses the preload element passed and sets the necessary link headers

publicvoidprependTitle(array|string $title)

Prepends a text to current document title

publicstringradioField(array|string $parameters)

Builds an HTML input[type=“radio”] tag

publicstringrangeField(array|string $parameters)

Builds an HTML input[type=“range”] tag

publicstringrenderAttributes(string $code,array $attributes)

Renders parameters keeping order in their HTML attributes

publicstringrenderTitle(bool $prepend = true,bool $append = true)

Renders the title with title tags. The title is automatically escaped

publicvoidresetInput()

Resets the request and internal values to avoid those fields will have

publicstringsearchField(array|string $parameters)

Builds a HTML input[type=“search”] tag

publicstringselect(array|string $parameters,mixed $data = null)

Builds a HTML SELECT tag using a Phalcon\Mvc\Model resultset as options

publicstringselectStatic(array|string $parameters,mixed $data = null)

Builds an HTML SELECT tag using a PHP array for options

publicvoidsetAutoescape(bool $autoescape)

Set autoescape mode in generated HTML

publicvoidsetDI(DiInterface $container)

Sets the dependency injector container.

publicvoidsetDefault(string $id,mixed $value = null)

Assigns default values to generated tags by helpers

publicvoidsetDefaults(array $values,bool $merge = false)

Assigns default values to generated tags by helpers

publicvoidsetDocType(int $doctype)

Set the document type of content

publicvoidsetTitle(string $title)

Set the title of view content

publicvoidsetTitleSeparator(string $titleSeparator)

Set the title separator of view content

publicstringstylesheetLink(array|string|null $parameters = null,bool $local = true)

Builds a LINK[rel=“stylesheet”] tag

publicstringsubmitButton(array|string $parameters)

Builds an HTML input[type=“submit”] tag

publicstringtagHtml(string $tagName,array|string $parameters = [],bool $selfClose = false,bool $onlyStart = false,bool $useEol = false)

Builds a HTML tag

publicstringtagHtmlClose(string $tagName,bool $useEol = false)

Builds a HTML tag closing tag

publicstringtelField(array|string $parameters)

Builds an HTML input[type=“tel”] tag

publicstringtextArea(array|string $parameters)

Builds an HTML TEXTAREA tag

publicstringtextField(array|string $parameters)

Builds an HTML input[type=“text”] tag

publicstringtimeField(array|string $parameters)

Builds an HTML input[type=“time”] tag

publicstringurlField(array|string $parameters)

Builds an HTML input[type=“url”] tag

publicstringweekField(array|string $parameters)

Builds an HTML input[type=“week”] tag

protectedstringgetStaticUrl(mixed $uri)

Resolves a static (asset) URL through the url service.

protectedstringinputField(string $type,array|string $parameters,bool $asValue = false)

Builds generic INPUT tags

protectedstringinputFieldChecked(string $type,array|string $parameters)

Builds INPUT tags that implements the checked attribute

protectedstringtoStringValue(mixed $value)

Reduces an arbitrary helper value to the string a tag attribute, id or

Constants

intHTML32 = 1
intHTML401_FRAMESET = 4
intHTML401_STRICT = 2
intHTML401_TRANSITIONAL = 3
intHTML5 = 5
intXHTML10_FRAMESET = 8
intXHTML10_STRICT = 6
intXHTML10_TRANSITIONAL = 7
intXHTML11 = 9
intXHTML20 = 10
intXHTML5 = 11

Properties

protectedbool$autoEscape = true
protectedDiInterface|null$container = null
protectedarray$displayValues = []
protectedarray$documentAppendTitle = []
protectedarray$documentPrependTitle = []
protectedstring|null$documentTitle = ""
protectedstring|null$documentTitleSeparator = ""
protectedint$documentType = 11
protectedEscaperInterface|null$escaperService = null
protectedUrlInterface|null$urlService = null

Methods

Public · 56

appendTitle()

public static function appendTitle( array|string $title ): void;

Appends a text to current document title

checkField()

public static function checkField( array|string $parameters ): string;

Builds an HTML input[type=“check”] tag

colorField()

public static function colorField( array|string $parameters ): string;

Builds an HTML input[type=“color”] tag

dateField()

public static function dateField( array|string $parameters ): string;

Builds an HTML input[type=“date”] tag

dateTimeField()

public static function dateTimeField( array|string $parameters ): string;

Builds an HTML input[type=“datetime”] tag

dateTimeLocalField()

public static function dateTimeLocalField( array|string $parameters ): string;

Builds an HTML input[type=“datetime-local”] tag

displayTo()

public static function displayTo(
    string $id,
    mixed $value
): void;

Alias of Phalcon\Tag::setDefault()

emailField()

public static function emailField( array|string $parameters ): string;

Builds an HTML input[type=“email”] tag

endForm()

public static function endForm(): string;

Builds an HTML close FORM tag

fileField()

public static function fileField( array|string $parameters ): string;

Builds an HTML input[type=“file”] tag

formLegacy()

public static function formLegacy( array|string $parameters ): string;

Builds an HTML FORM tag

friendlyTitle()

public static function friendlyTitle(
    string $text,
    string $separator = "-",
    bool $lowercase = true,
    array|string $replace = []
): string;

Converts texts into URL-friendly titles

getDI()

public static function getDI(): DiInterface;

Internally gets the request dispatcher

getDocType()

public static function getDocType(): string;

Get the document type declaration of content

getEscaper()

public static function getEscaper( array $parameters ): EscaperInterface|null;

Obtains the ‘escaper’ service if required

getEscaperService()

public static function getEscaperService(): EscaperInterface;

Returns an Escaper service from the default DI

getTitle()

public static function getTitle(
    bool $prepend = true,
    bool $append = true
): string;

Gets the current document title. The title will be automatically escaped.

getTitleSeparator()

public static function getTitleSeparator(): string;

Gets the current document title separator

getUrlService()

public static function getUrlService(): UrlInterface;

Returns a URL service from the default DI

getValue()

public static function getValue(
    int|string $name,
    array $parameters = []
): mixed;

Every helper calls this function to check whether a component has a predefined value using Phalcon\Tag::setDefault() or value from $_POST

hasValue()

public static function hasValue( int|string $name ): bool;

Check if a helper has a default value set using Phalcon\Tag::setDefault() or value from $_POST

hiddenField()

public static function hiddenField( array|string $parameters ): string;

Builds a HTML input[type=“hidden”] tag

image()

public static function image(
    array|string $parameters = [],
    bool $local = true
): string;

Builds HTML IMG tags

imageInput()

public static function imageInput( array|string $parameters ): string;

Builds an HTML input[type=“image”] tag

javascriptInclude()

public static function javascriptInclude(
    array|string $parameters = [],
    bool $local = true
): string;

Builds a SCRIPT[type=“javascript”] tag

linkTo()

public static function linkTo(
    array|string $parameters,
    string|null $text = null,
    bool $local = true
): string;

Builds an HTML A tag using framework conventions

monthField()

public static function monthField( array|string $parameters ): string;

Builds an HTML input[type=“month”] tag

numericField()

public static function numericField( array|string $parameters ): string;

Builds an HTML input[type=“number”] tag

passwordField()

public static function passwordField( array|string $parameters ): string;

Builds a HTML input[type=“password”] tag

preload()

public static function preload( array|string $parameters ): string;

Parses the preload element passed and sets the necessary link headers

prependTitle()

public static function prependTitle( array|string $title ): void;

Prepends a text to current document title

radioField()

public static function radioField( array|string $parameters ): string;

Builds an HTML input[type=“radio”] tag

rangeField()

public static function rangeField( array|string $parameters ): string;

Builds an HTML input[type=“range”] tag

renderAttributes()

public static function renderAttributes(
    string $code,
    array $attributes
): string;

Renders parameters keeping order in their HTML attributes

renderTitle()

public static function renderTitle(
    bool $prepend = true,
    bool $append = true
): string;

Renders the title with title tags. The title is automatically escaped

resetInput()

public static function resetInput(): void;

Resets the request and internal values to avoid those fields will have any default value.

searchField()

public static function searchField( array|string $parameters ): string;

Builds a HTML input[type=“search”] tag

select()

public static function select(
    array|string $parameters,
    mixed $data = null
): string;

Builds a HTML SELECT tag using a Phalcon\Mvc\Model resultset as options

selectStatic()

public static function selectStatic(
    array|string $parameters,
    mixed $data = null
): string;

Builds an HTML SELECT tag using a PHP array for options

setAutoescape()

public static function setAutoescape( bool $autoescape ): void;

Set autoescape mode in generated HTML

setDI()

public static function setDI( DiInterface $container ): void;

Sets the dependency injector container.

setDefault()

public static function setDefault(
    string $id,
    mixed $value = null
): void;

Assigns default values to generated tags by helpers

setDefaults()

public static function setDefaults(
    array $values,
    bool $merge = false
): void;

Assigns default values to generated tags by helpers

setDocType()

public static function setDocType( int $doctype ): void;

Set the document type of content

setTitle()

public static function setTitle( string $title ): void;

Set the title of view content

setTitleSeparator()

public static function setTitleSeparator( string $titleSeparator ): void;

Set the title separator of view content

public static function stylesheetLink(
    array|string|null $parameters = null,
    bool $local = true
): string;

Builds a LINK[rel=“stylesheet”] tag

submitButton()

public static function submitButton( array|string $parameters ): string;

Builds an HTML input[type=“submit”] tag

tagHtml()

public static function tagHtml(
    string $tagName,
    array|string $parameters = [],
    bool $selfClose = false,
    bool $onlyStart = false,
    bool $useEol = false
): string;

Builds a HTML tag

tagHtmlClose()

public static function tagHtmlClose(
    string $tagName,
    bool $useEol = false
): string;

Builds a HTML tag closing tag

telField()

public static function telField( array|string $parameters ): string;

Builds an HTML input[type=“tel”] tag

textArea()

public static function textArea( array|string $parameters ): string;

Builds an HTML TEXTAREA tag

textField()

public static function textField( array|string $parameters ): string;

Builds an HTML input[type=“text”] tag

timeField()

public static function timeField( array|string $parameters ): string;

Builds an HTML input[type=“time”] tag

urlField()

public static function urlField( array|string $parameters ): string;

Builds an HTML input[type=“url”] tag

weekField()

public static function weekField( array|string $parameters ): string;

Builds an HTML input[type=“week”] tag

Protected · 4

getStaticUrl()

final protected static function getStaticUrl( mixed $uri ): string;

Resolves a static (asset) URL through the url service.

getStatic() lives on Phalcon\Mvc\Url but is absent from Phalcon\Mvc\Url\UrlInterface, which is what getUrlService() is typed to return. A service that does not carry it falls back to get() rather than aborting the helper.

inputField()

final protected static function inputField(
    string $type,
    array|string $parameters,
    bool $asValue = false
): string;

Builds generic INPUT tags

inputFieldChecked()

final protected static function inputFieldChecked(
    string $type,
    array|string $parameters
): string;

Builds INPUT tags that implements the checked attribute

toStringValue()

final protected static function toStringValue( mixed $value ): string;

Reduces an arbitrary helper value to the string a tag attribute, id or URI needs. Parameter bags are user supplied, so a value that cannot be expressed as a string - an array, an object without __toString() - reads back as an empty string rather than aborting the helper.

Tag\Exception

ClassSource on GitHub

Exceptions thrown in Phalcon\Tag will use this class

  • \Exception
    • Phalcon\Tag\Exception

Tag\Select

AbstractSource on GitHub

Phalcon\Tag\Select

Generates a SELECT HTML tag using a static array of values or a Phalcon\Mvc\Model resultset

  • Phalcon\Tag\Select

Uses Closure · Phalcon\Mvc\Model\ResultsetInterface · Phalcon\Tag · Stringable

Method Summary

Constants

stringOPTION_CLOSE = "</option>"
stringSELECT_CLOSE = "</select>"

Methods

Public · 1

selectField()

public static function selectField(
    array|string $parameters,
    mixed $data = null
): string;

Generates a SELECT tag

Protected · 2

echoOption()

protected static function echoOption(
    string $value,
    bool $selected = false
): string;

toStringValue()

protected static function toStringValue( mixed $value ): string;

Reduces an arbitrary option value to the string the markup needs. Option data is user supplied, so anything that cannot be expressed as a string reads back as an empty string rather than aborting the tag.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close