Show:

Q_Html Class

Module: Q

This class lets you output various HTML markup tags

Item Index

Methods

Properties

Methods

a

(
  • $href
  • [$attributes=array()]
  • [$contents=null]
)
String static

Generates markup for a link element

Parameters:

  • $href String | Q_Uri

    Could be a URL string, a Q_Uri object, or a string representing a Q_Uri object.

  • [$attributes=array()] Array optional

    An associative array of additional attributes.

  • [$contents=null] String optional

    If null, only the opening tag is generated. If a string, also inserts the contents and generates a closing tag. If you want to do escaping on the contents, you must do it yourself. If true, auto-closes the tag.

Returns:

String:

The generated markup

attributes

(
  • $attributes
  • [$between='
  • [$escape=true]
  • [$tag=null]
  • [$options=array()]
)
String protected static

Generates a string from an attribute array

Parameters:

  • $attributes Array

    Associative array of name => value pairs.

  • [$between=' String

    '] The text to insert between the attribute="value"

  • [$escape=true] String optional

    Whether to escape the attribute names and values.

  • [$tag=null] String optional
  • [$options=array()] Array optional
    • [ignoreEnvironment=false] Boolean optional

      If true, doesn't apply environment transformations

    • [hash=null] String optional

      If URL was already processed with cachedUrlAndCache, set hash here to avoid calling it again

Returns:

String:

buttons

(
  • $name
  • $list
  • [$ids='']
  • [$between='']
  • [$attributes=array()]
)
String static

Renders a series of buttons from an associative array we already have

Parameters:

  • $name String

    The name of the input

  • $list Array

    Associative array of value => caption.

  • [$ids=''] Array optional

    Either an associative array of key => id (in the HTML element sense) pairs, or

  • [$between=''] String optional

    The text to insert in the markup between the generated elements

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs.

Returns:

String:

The generated markup

checkboxes

(
  • $name
  • $list
  • [$ids='']
  • [$checked=array()]
  • [$between='']
  • [$attributes=array()]
)
String static

Renders a series of checkboxes from an associative array we already have

Parameters:

  • $name String

    The name of the input

  • $list Array

    Associative array of value => caption.

  • [$ids=''] Array optional

    Either an associative array of key => id (in the HTML element sense) pairs, or a string. If a string, then a counter (1, 2, 3) is appended to each subsequent id.

  • [$checked=array()] Array | String optional

    The name of a single key, or an array indicating which checkboxes are checked. If a key from $list is present as a key in this array, that checkbox is checked.

  • [$between=''] String optional

    The text to insert in the markup between the generated elements

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs.

Returns:

String:

The generated markup

copyAttributes

(
  • $attributes
  • $key
)
Array protected static

Copies attributes from a given array. Traverses the $attributes array. If the value is a string, copies it over. If it is an array, checks whether it contains $key and if it does, copies the value over.

Parameters:

  • $attributes Array

    An associative array of attributes

  • $key String

    The key of the field being considered.

Returns:

Array:

date

(
  • $name
  • [$value=null]
  • [$options=null]
  • [$attributes=array()]
)
String static

Renders a date selector

Parameters:

  • $name String

    The name of the input

  • [$value=null] String optional

    You can put a date here, as a string

  • [$options=null] Array optional

    Options include the following:

    • "year_from" => the first year in the selector
    • "year_to" => the last year in the selector
  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs.

Returns:

String:

The generated markup

div

(
  • $id
  • [$class='']
  • [$attributes=array()]
  • [$content=null]
)
String static

Renders a div with some id and classes

Parameters:

  • $id String

    The id of the div. It will be prefixed with the current id prefix.

  • [$class=''] String optional

    classes of the div. Could be a string or an array of strings.

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs.

  • [$content=null] String optional

    The content of the label

Returns:

String:

The generated markup

email

(
  • [subject]
  • [body]
  • [to]
  • [cc]
  • [bcc]
)
String static

Generates a link for sending an email message

Parameters:

  • [subject] String optional
  • [body] String optional
  • [to] String | Array optional
  • [cc] String | Array optional
  • [bcc] String | Array optional

Returns:

String:

form

(
  • [$action='']
  • [$method='post']
  • [$attributes=array()]
  • [$contents=null]
)
String static

Renders a form

Parameters:

  • [$action=''] String | Q_Uri optional

    Could be a URL string, a Q_Uri object, or a string representing a Q_Uri object.

  • [$method='post'] String optional

    The method for the form submission.

  • [$attributes=array()] Array optional

    An associative array of additional attributes. (say that 4 times fast)

  • [$contents=null] String optional

    If null, only the opening tag is generated. If a string, also inserts the contents and generates a closing tag. If you want to do escaping on the contents, you must do it yourself.

Returns:

String:

The generated markup

formInfo

(
  • $onSuccess
  • [$onErrors=null]
  • [$sessionNonceField=null]
)
String static

Renders Q-specific information for a form

Parameters:

  • $onSuccess String

    The URI or URL to redirect to in case of success If you put "true" here, it uses Q_Request::special('onSuccess', $uri), or if it's not there, then Q_Dispatcher::uri()

  • [$onErrors=null] String optional

    The URI or URL to redirect to in case of errors If you put "true" here, it uses Q_Request::special('onErrors', $uri), or if it's not there, then Q_Dispatcher::uri()

  • [$sessionNonceField=null] String optional

    The name of the nonce field to use in the session. If the config parameter "Q"/"session"/"nonceField" is set, uses that.

Returns:

String:

The generated markup

getIdPrefix

(
  • toolName
)
String | Null static

The current prefix that will be applied to all ids rendered by Q_Html.

Parameters:

  • toolName String

    Optional name of the tool that is being rendered

Returns:

String | Null:

The prefix that is currently at the top of the prefix stack.

getToolIds

() Array static

The ids of tools rendered on this element

Returns:

Array:

The tool ids array that is currently at the top of the prefix stack.

hidden

(
  • [$list=array()]
  • [$keys=null]
  • [$class_attributes=true]
)
static

Renders a bunch of hidden inputs

Parameters:

  • [$list=array()] Array optional

    An associative array of fieldname => fieldvalue pairs.

  • [$keys=null] Array | String optional

    An array of keys to precede the keys in the associative array. If a string is passed, it becomes the name of the field (array). Defaults to empty. Used mainly during recursion.

  • [$class_attributes=true] Boolean optional

    Defaults to true. If true, generates the class attribute from the name of each field.

id

(
  • $id
  • [$prefix]
)
String static

Returns an HTML element ID, constrained to alphanumeric characters with dashes and underscores, and possibly prefixed.

Parameters:

  • $id String

    Any string

  • [$prefix] String optional

    To override the default prefix

Returns:

String:

img

(
  • $src
  • [$alt='image']
  • [$attributes=array()]
)
String static

Renders an img tag

Parameters:

  • $src String

    The source of the image. Will be subjected to theming before being rendered.

  • [$alt='image'] String optional

    The alternative text to display in place of the image.

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs. Can also contain "cacheBust" => milliseconds, to use Q_Uri::cacheBust on the src.

Returns:

String:

The generated markup

input

(
  • $name
  • $value
  • [$attributes=array()]
)
String static

Renders a form input

Parameters:

  • $name String

    The name of the input. Will be sanitized.

  • $value String

    The value of the input. Will be sanitized.

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs.

Returns:

String:

The generated markup

json

(
  • $content
)
String static

Escapes a string, so it can be outputted within javascript. Note that this can be used within js files as well as inline scripts. However, inline scripts should be html-escaped or enclosed within <![CDATA[ ... ]]> So use Html::script().

Parameters:

  • $content String

    The string to escape

Returns:

String:

label

(
  • $for
  • [$attributes=array()]
  • [$contents=null]
)
String static

Renders a label for some element

Parameters:

  • $for String

    The id of the element the label is tied to. It will be prefixed with the current id prefix

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs.

  • [$contents=null] String optional

    The contents of the label

Returns:

String:

The generated markup

options

(
  • $list
  • [$ids='']
  • [$selected=null]
  • [$includeBlank=null]
  • [$between='']
  • [$attributes=array()]
)
String static

Renders a series of options for a select tag from an associative array we already have

Parameters:

  • $list Array

    Associative array of value => caption.

  • [$ids=''] Array optional

    Either an associative array of key => id (in the HTML element sense) pairs, or a prefix to which autogenerated ids will be appended

  • [$selected=null] String | Integer optional

    The name of a single key, or an array indicating which options are selected. If a key from $list is present as a key in this array, that option is selected.

  • [$includeBlank=null] String optional

    If null, don't include a blank option. Otherwise, make a blank item (with value="") and caption=$includeBlank if it's a string, or "" otherwise.

  • [$between=''] String optional

    The text to insert in the markup between the generated elements. Since this text won't be shown in the browser, it's just for source formatting purposes.

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs.

Returns:

String:

The generated markup

popIdPrefix

() String | Null static

Pops the last id prefix. Now all ids rendered by Q_Html will be prefixed with the id previously on top of the stack, if any.

Returns:

String | Null:

The prefix that has been popped, if any

pushIdPrefix

(
  • $id_prefix
  • $tool_ids
)
String | Null static

Sets a new id prefix to prefix all ids rendered by Html. It gets pushed on top of the stack and can be pieped later.

Parameters:

  • $id_prefix String

    The prefix to apply to all ids rendered by Html after this

  • $tool_ids Array

    The ids of tools rendered on this element

Returns:

String | Null:

The prefix previously on top of the stack, if any

pushThemeUrl

(
  • $theme
)
Array static

Pushes a new theme url to the end of the cascade -- if a theme file doesn't exist, we go backwards through the cascade and if we locate it under a previous theme url, we use that one. NOTE: If your webserver supports .htaccess files, you can implement cascading themes much more efficiently: simply push ONE theme url using this function, and implement the cascade using .htaccess files.

Parameters:

  • $theme String

    The url to be prepended to all non-absolute "src" attributes (except for iframes) rendered by Q_Html

Returns:

Array:

The new list of themes

query

(
  • $fields
  • [$more_fields=array()]
)
String static

Generates a querystring based on the current $_GET

Parameters:

  • $fields Array

    Associative array. The keys are the fields to take from $_GET, the values are the defaults.

  • [$more_fields=array()] Array optional

    The array to merge over the query array before building the querystring.

Returns:

String:

The resulting querystring.

radios

(
  • $name
  • $list
  • [$ids='']
  • [$selectedKey=null]
  • [$between='']
  • [$attributes=array()]
)
String static

Renders a series of radio buttons from an associative array we already have

Parameters:

  • $name String

    The name of the input

  • $list Array

    Associative array of value => caption.

  • [$ids=''] Array optional

    Either an associative array of key => id (in the HTML element sense) pairs, or

  • [$selectedKey=null] String optional

    Basically the value of the selected radiobutton

  • [$between=''] String optional

    The text to insert in the markup between the generated elements

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs.

Returns:

String:

The generated markup

render

(
  • $object
)
String static

Parameters:

  • $object Mixed

Returns:

String:

script

(
  • $script
  • [$attributes=null]
)
String static

Renders a script (probably a javascript)

Parameters:

  • $script String

    The actual script, as text

  • [$attributes=null] Array optional

    Any additional attributes. Also can include: "cdata" => Defaults to true. Whether to enclose in CDATA tags. "comment" => Whether to enclose in HTML comments "raw" => Set to true to skip HTML encoding even if cdata and comment are false "cacheBust" => milliseconds, to use Q_Uri::cacheBust on the src.

Returns:

String:

The generated markup.

select

(
  • $name
  • [$attributes=array()]
  • $contents
)
String static

Renders a select tag

Parameters:

  • $name String

    The name of the input. Will be sanitized..

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs.

  • $contents String

    Defaults to null, but you can place the output of Q_Html::options here.

Returns:

String:

The generated markup

smartTag

(
  • $type
  • [$attributes=array()]
  • [$value=null]
  • [$options=null]
  • [$params=array()]
)
String static

Renders a different tag based on what you specified.

Parameters:

  • $type String

    The type of the tag. Could be one of 'static', 'boolean', 'text', 'email', 'tel', 'textarea', 'password', 'select', 'radios', 'checkboxes', 'buttons', 'submit_buttons', 'submit', 'hidden', 'image', or the name of a tag.

  • [$attributes=array()] Array | String optional

    The attributes for the resulting element. Should at least include the name. You can also just pass the name as a string here.

  • [$value=null] Array optional

    The value to start out with in the resulting element. If there are options present, this should be the value of one of the options.

  • [$options=null] Array optional

    Associative array of options, used if the tag type is 'select', 'radios' or 'checkboxes'.

  • [$params=array()] Array optional

    Additional parameters to pass to the corresponding function

Returns:

String:

The generated markup

sms

(
  • [$body]
  • [$mobileNumbers]
)
String static

Generates a link for sending an sms message

Parameters:

  • [$body] String optional
  • [$mobileNumbers] String | Array optional

Returns:

String:

swf

(
  • $movie_url
  • [$flash_params=array()]
  • [$attributes=array()]
)
String static

Renders an swf object using the standard <object> tag, which hopefully all new modern browsers already support.

Parameters:

  • $movie_url String

    The (relative or absolute) url of the movie

  • [$flash_params=array()] Array optional

    An array of additional <param> elements to render within the <object> element. Consists of name => value pairs. Note that the parameter with name="movie" is always rendered.

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs. Don't forget to include "codebase", "width", "height" and "classid" Can also contain "cacheBust" => milliseconds, to use Q_Uri::cacheBust on the src.

Returns:

String:

The resulting markup

tag

(
  • $tag
  • [$attributes=array()]
  • [$contents=null]
  • [$options=array()]
)
String static

Renders an arbitrary HTML tag

Parameters:

  • $tag String

    The tag name of the element

  • [$attributes=array()] Array optional

    An array of additional attributes to render. Consists of name => value pairs. Can also contain "cacheBust" => milliseconds, to use Q_Uri::cacheBust on the src.

  • [$contents=null] String optional

    If null, only the opening tag is generated. If a string, also inserts the contents and generates a closing tag. If you want to do escaping on the contents, you must do it yourself. If true, auto-closes the tag.

  • [$options=array()] Array optional
    • [ignoreEnvironment=false] Boolean optional

      If true, doesn't apply environment transformations

    • [hash=null] String optional

      If URL was already processed with cachedUrlAndCache, set hash here to avoid calling it again

Returns:

String:

text

(
  • $content
  • [$convert=array()]
  • [$unconvert=array()]
)
String static

Escapes a string, converting all HTML entities into plain text equivalents.

Parameters:

  • $content String

    The string to escape

  • [$convert=array()] String optional

    An array of additional characters to convert. Can include "\n" and " ".

  • [$unconvert=array()] String optional

    An array of from => to pairs to unconvert back.

Returns:

String:

textarea

(
  • $name
  • $rows
  • $cols
  • array
  • [$contents=null]
)
String static

Renders a textarea in a form

Parameters:

  • $name String

    The name of the input. Will be sanitized.

  • $rows String

    The number of rows in the textarea.

  • $cols String

    The number of columns in the textarea.

  • array Object

    [$attributes=array()] An array of additional attributes to render. Consists of name => value pairs.

  • [$contents=null] String optional

    If null, only the opening tag is generated. If a string, also inserts the contents and generates a closing tag. If you want to do escaping on the contents, you must do it yourself.

Returns:

String:

The generated markup

themedFilename

(
  • $filePath
  • [$options=array()]
)
static

Gets the filename of a themed file

Parameters:

  • $filePath String

    Basically the subpath of the file underneath the web or theme directory

  • [$options=array()] Array optional
    • [ignoreEnvironment=false] Boolean optional

      If true, doesn't apply environment transformations

    • [hash=null] String optional

      If URL was already processed with cachedUrlAndCache, set hash here to avoid calling it again

themedUrl

(
  • $filePath
  • [$options=array()]
)
String static

Gets the url of a themed file

Parameters:

  • $filePath String

    Basically the subpath of the file underneath the web or theme directory

  • [$options=array()] Array optional
    • [ignoreEnvironment=false] Boolean optional

      If true, doesn't apply environment transformations

    • [hash=null] String optional

      If URL was already processed with cachedUrlAndCache, set hash here to avoid calling it again

Returns:

String:

The themed url.

themedUrlFilenameAndHash

(
  • $filePath
  • [$options=array()]
)
Array static

Gets the url and filename of a themed file

Parameters:

  • $filePath String

    Basically the subpath of the file underneath the web or theme directory

  • [$options=array()] Array optional
    • [ignoreEnvironment=false] Boolean optional

      If true, doesn't apply environment transformations

    • [hash=null] String optional

      If URL was already processed with cachedUrlAndCache, set hash here to avoid calling it again

Returns:

Array:

A three-element array containing the url, filename, hash

themeUrl

() String | Null static

The current theme url applied to all "src" attributes (except for iframes) rendered by Q_Html.

Returns:

String | Null:

The theme url that is currently at the end of the cascade, i.e. was pushed last.

truncate

(
  • $text
  • [$length=20]
  • [$replace='...']
  • [$last_word_max_length=0]
  • [$guarantee_result_length=true]
)
String static

Truncates some text to a length, returns result

Parameters:

  • $text String

    The text to truncate

  • [$length=20] Integer optional

    Length to truncate to. Defaults to 20

  • [$replace='...'] String optional

    String to replace truncated text. Defaults to three dots.

  • [$last_word_max_length=0] Integer optional

    The maximum length of the last word. If a positive number, adds the last word up to this length, truncating the text before it.

  • [$guarantee_result_length=true] String optional

    If true, then the result will definitely have a string length <= $length. If false, then it might be longer, as the length of $replace is not factored in.

Returns:

String:

Properties

$id_prefix

String protected static

The id prefix to be prepended to all ids passed in

$id_prefixes

Array protected static

The stack of id prefixes

$id_prefixes

Array protected static

The stack of tool id arrays

$theme

String protected static

The theme url to be used in various methods of this class.

$themes

Array protected static

The cascade of theme urls

Events

Q/themedUrlFilenameAndHash

Before

Event Payload:

  • file_path String