Q_Html Class
This class lets you output various HTML markup tags
Item Index
Methods
- a static
- attributes static
- buttons static
- checkboxes static
- copyAttributes static
- date static
- div static
- email static
- form static
- formInfo static
- getIdPrefix static
- getToolIds static
- hidden static
- id static
- img static
- input static
- json static
- label static
- options static
- popIdPrefix static
- pushIdPrefix static
- pushThemeUrl static
- query static
- radios static
- render static
- script static
- select static
- smartTag static
- sms static
- swf static
- tag static
- text static
- textarea static
- themedFilename static
- themedUrl static
- themedUrlFilenameAndHash static
- themeUrl static
- truncate static
Properties
- $id_prefix static
- $id_prefixes static
- $id_prefixes static
- $theme static
- $themes static
Events
Methods
a
-
$href -
[$attributes=array()] -
[$contents=null]
Generates markup for a link element
Parameters:
-
$hrefString | Q_UriCould be a URL string, a Q_Uri object, or a string representing a Q_Uri object.
-
[$attributes=array()]Array optionalAn associative array of additional attributes.
-
[$contents=null]String optionalIf 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:
The generated markup
attributes
-
$attributes -
[$between=' -
[$escape=true] -
[$tag=null] -
[$options=array()]
Generates a string from an attribute array
Parameters:
-
$attributesArrayAssociative array of name => value pairs.
-
[$between='String'] The text to insert between the attribute="value"
-
[$escape=true]String optionalWhether to escape the attribute names and values.
-
[$tag=null]String optional -
[$options=array()]Array optional-
[ignoreEnvironment=false]Boolean optionalIf true, doesn't apply environment transformations
-
[hash=null]String optionalIf URL was already processed with cachedUrlAndCache, set hash here to avoid calling it again
-
Returns:
checkboxes
-
$name -
$list -
[$ids=''] -
[$checked=array()] -
[$between=''] -
[$attributes=array()]
Renders a series of checkboxes from an associative array we already have
Parameters:
-
$nameStringThe name of the input
-
$listArrayAssociative array of value => caption.
-
[$ids='']Array optionalEither 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 optionalThe 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 optionalThe text to insert in the markup between the generated elements
-
[$attributes=array()]Array optionalAn array of additional attributes to render. Consists of name => value pairs.
Returns:
The generated markup
copyAttributes
-
$attributes -
$key
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:
-
$attributesArrayAn associative array of attributes
-
$keyStringThe key of the field being considered.
Returns:
date
-
$name -
[$value=null] -
[$options=null] -
[$attributes=array()]
Renders a date selector
Parameters:
-
$nameStringThe name of the input
-
[$value=null]String optionalYou can put a date here, as a string
-
[$options=null]Array optionalOptions include the following:
- "year_from" => the first year in the selector
- "year_to" => the last year in the selector
-
[$attributes=array()]Array optionalAn array of additional attributes to render. Consists of name => value pairs.
Returns:
The generated markup
div
-
$id -
[$class=''] -
[$attributes=array()] -
[$content=null]
Renders a div with some id and classes
Parameters:
-
$idStringThe id of the div. It will be prefixed with the current id prefix.
-
[$class='']String optionalclasses of the div. Could be a string or an array of strings.
-
[$attributes=array()]Array optionalAn array of additional attributes to render. Consists of name => value pairs.
-
[$content=null]String optionalThe content of the label
Returns:
The generated markup
email
-
[subject] -
[body] -
[to] -
[cc] -
[bcc]
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:
form
-
[$action=''] -
[$method='post'] -
[$attributes=array()] -
[$contents=null]
Renders a form
Parameters:
-
[$action='']String | Q_Uri optionalCould be a URL string, a Q_Uri object, or a string representing a Q_Uri object.
-
[$method='post']String optionalThe method for the form submission.
-
[$attributes=array()]Array optionalAn associative array of additional attributes. (say that 4 times fast)
-
[$contents=null]String optionalIf 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:
The generated markup
formInfo
-
$onSuccess -
[$onErrors=null] -
[$sessionNonceField=null]
Renders Q-specific information for a form
Parameters:
-
$onSuccessStringThe 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 optionalThe 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 optionalThe name of the nonce field to use in the session. If the config parameter "Q"/"session"/"nonceField" is set, uses that.
Returns:
The generated markup
getIdPrefix
-
toolName
The current prefix that will be applied to all ids rendered by Q_Html.
Parameters:
-
toolNameStringOptional name of the tool that is being rendered
Returns:
The prefix that is currently at the top of the prefix stack.
getToolIds
()
Array
static
The ids of tools rendered on this element
Returns:
The tool ids array that is currently at the top of the prefix stack.
id
-
$id -
[$prefix]
Returns an HTML element ID, constrained to alphanumeric characters with dashes and underscores, and possibly prefixed.
Parameters:
-
$idStringAny string
-
[$prefix]String optionalTo override the default prefix
Returns:
img
-
$src -
[$alt='image'] -
[$attributes=array()]
Renders an img tag
Parameters:
-
$srcStringThe source of the image. Will be subjected to theming before being rendered.
-
[$alt='image']String optionalThe alternative text to display in place of the image.
-
[$attributes=array()]Array optionalAn 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:
The generated markup
input
-
$name -
$value -
[$attributes=array()]
Renders a form input
Parameters:
-
$nameStringThe name of the input. Will be sanitized.
-
$valueStringThe value of the input. Will be sanitized.
-
[$attributes=array()]Array optionalAn array of additional attributes to render. Consists of name => value pairs.
Returns:
The generated markup
json
-
$content
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:
-
$contentStringThe string to escape
Returns:
label
-
$for -
[$attributes=array()] -
[$contents=null]
Renders a label for some element
Parameters:
-
$forStringThe id of the element the label is tied to. It will be prefixed with the current id prefix
-
[$attributes=array()]Array optionalAn array of additional attributes to render. Consists of name => value pairs.
-
[$contents=null]String optionalThe contents of the label
Returns:
The generated markup
options
-
$list -
[$ids=''] -
[$selected=null] -
[$includeBlank=null] -
[$between=''] -
[$attributes=array()]
Renders a series of options for a select tag from an associative array we already have
Parameters:
-
$listArrayAssociative array of value => caption.
-
[$ids='']Array optionalEither 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 optionalThe 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 optionalIf 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 optionalThe 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 optionalAn array of additional attributes to render. Consists of name => value pairs.
Returns:
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:
The prefix that has been popped, if any
pushIdPrefix
-
$id_prefix -
$tool_ids
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_prefixStringThe prefix to apply to all ids rendered by Html after this
-
$tool_idsArrayThe ids of tools rendered on this element
Returns:
The prefix previously on top of the stack, if any
pushThemeUrl
-
$theme
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:
-
$themeStringThe url to be prepended to all non-absolute "src" attributes (except for iframes) rendered by Q_Html
Returns:
The new list of themes
query
-
$fields -
[$more_fields=array()]
Generates a querystring based on the current $_GET
Parameters:
-
$fieldsArrayAssociative array. The keys are the fields to take from $_GET, the values are the defaults.
-
[$more_fields=array()]Array optionalThe array to merge over the query array before building the querystring.
Returns:
The resulting querystring.
radios
-
$name -
$list -
[$ids=''] -
[$selectedKey=null] -
[$between=''] -
[$attributes=array()]
Renders a series of radio buttons from an associative array we already have
Parameters:
-
$nameStringThe name of the input
-
$listArrayAssociative array of value => caption.
-
[$ids='']Array optionalEither an associative array of key => id (in the HTML element sense) pairs, or
-
[$selectedKey=null]String optionalBasically the value of the selected radiobutton
-
[$between='']String optionalThe text to insert in the markup between the generated elements
-
[$attributes=array()]Array optionalAn array of additional attributes to render. Consists of name => value pairs.
Returns:
The generated markup
render
-
$object
Parameters:
-
$objectMixed
Returns:
script
-
$script -
[$attributes=null]
Renders a script (probably a javascript)
Parameters:
-
$scriptStringThe actual script, as text
-
[$attributes=null]Array optionalAny 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:
The generated markup.
select
-
$name -
[$attributes=array()] -
$contents
Renders a select tag
Parameters:
-
$nameStringThe name of the input. Will be sanitized..
-
[$attributes=array()]Array optionalAn array of additional attributes to render. Consists of name => value pairs.
-
$contentsStringDefaults to null, but you can place the output of Q_Html::options here.
Returns:
The generated markup
smartTag
-
$type -
[$attributes=array()] -
[$value=null] -
[$options=null] -
[$params=array()]
Renders a different tag based on what you specified.
Parameters:
-
$typeStringThe 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 optionalThe 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 optionalThe 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 optionalAssociative array of options, used if the tag type is 'select', 'radios' or 'checkboxes'.
-
[$params=array()]Array optionalAdditional parameters to pass to the corresponding function
Returns:
The generated markup
sms
-
[$body] -
[$mobileNumbers]
Generates a link for sending an sms message
Parameters:
-
[$body]String optional -
[$mobileNumbers]String | Array optional
Returns:
swf
-
$movie_url -
[$flash_params=array()] -
[$attributes=array()]
Renders an swf object using the standard <object> tag, which hopefully all new modern browsers already support.
Parameters:
-
$movie_urlStringThe (relative or absolute) url of the movie
-
[$flash_params=array()]Array optionalAn 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 optionalAn 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:
The resulting markup
tag
-
$tag -
[$attributes=array()] -
[$contents=null] -
[$options=array()]
Renders an arbitrary HTML tag
Parameters:
-
$tagStringThe tag name of the element
-
[$attributes=array()]Array optionalAn 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 optionalIf 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 optionalIf true, doesn't apply environment transformations
-
[hash=null]String optionalIf URL was already processed with cachedUrlAndCache, set hash here to avoid calling it again
-
Returns:
text
-
$content -
[$convert=array()] -
[$unconvert=array()]
Escapes a string, converting all HTML entities into plain text equivalents.
Parameters:
-
$contentStringThe string to escape
-
[$convert=array()]String optionalAn array of additional characters to convert. Can include "\n" and " ".
-
[$unconvert=array()]String optionalAn array of from => to pairs to unconvert back.
Returns:
textarea
-
$name -
$rows -
$cols -
array -
[$contents=null]
Renders a textarea in a form
Parameters:
-
$nameStringThe name of the input. Will be sanitized.
-
$rowsStringThe number of rows in the textarea.
-
$colsStringThe number of columns in the textarea.
-
arrayObject[$attributes=array()] An array of additional attributes to render. Consists of name => value pairs.
-
[$contents=null]String optionalIf 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:
The generated markup
themedFilename
-
$filePath -
[$options=array()]
Gets the filename of a themed file
Parameters:
-
$filePathStringBasically the subpath of the file underneath the web or theme directory
-
[$options=array()]Array optional-
[ignoreEnvironment=false]Boolean optionalIf true, doesn't apply environment transformations
-
[hash=null]String optionalIf URL was already processed with cachedUrlAndCache, set hash here to avoid calling it again
-
themedUrl
-
$filePath -
[$options=array()]
Gets the url of a themed file
Parameters:
-
$filePathStringBasically the subpath of the file underneath the web or theme directory
-
[$options=array()]Array optional-
[ignoreEnvironment=false]Boolean optionalIf true, doesn't apply environment transformations
-
[hash=null]String optionalIf URL was already processed with cachedUrlAndCache, set hash here to avoid calling it again
-
Returns:
The themed url.
themedUrlFilenameAndHash
-
$filePath -
[$options=array()]
Gets the url and filename of a themed file
Parameters:
-
$filePathStringBasically the subpath of the file underneath the web or theme directory
-
[$options=array()]Array optional-
[ignoreEnvironment=false]Boolean optionalIf true, doesn't apply environment transformations
-
[hash=null]String optionalIf URL was already processed with cachedUrlAndCache, set hash here to avoid calling it again
-
Returns:
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:
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]
Truncates some text to a length, returns result
Parameters:
-
$textStringThe text to truncate
-
[$length=20]Integer optionalLength to truncate to. Defaults to 20
-
[$replace='...']String optionalString to replace truncated text. Defaults to three dots.
-
[$last_word_max_length=0]Integer optionalThe 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 optionalIf 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:
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_pathString