Methods summary
public static
string
|
#
encode( string $text )
Encodes special characters into HTML entities. The CApplication::charset application charset will be used for encoding.
Encodes special characters into HTML entities. The CApplication::charset application charset will be used for encoding.
Parameters
- $text
string $text data to be encoded
Returns
string the encoded data
See
|
public static
string
|
#
decode( string $text )
Decodes special HTML entities back to the corresponding characters. This is
the opposite of CHtml::encode() .
Decodes special HTML entities back to the corresponding characters. This is
the opposite of CHtml::encode() .
Parameters
- $text
string $text data to be decoded
Returns
string the decoded data
Since
1.1.8
See
|
public static
array
|
#
encodeArray( array $data )
Encodes special characters in an array of strings into HTML entities. Both
the array keys and values will be encoded if needed. If a value is an array,
this method will also encode it recursively. The CApplication::charset
application charset will be used for encoding.
Encodes special characters in an array of strings into HTML entities. Both
the array keys and values will be encoded if needed. If a value is an array,
this method will also encode it recursively. The CApplication::charset
application charset will be used for encoding.
Parameters
- $data
array $data data to be encoded
Returns
array the encoded data
See
|
public static
string
|
#
tag( string $tag, array $htmlOptions = array(), mixed $content = false, boolean $closeTag = true )
Generates an HTML element.
Generates an HTML element.
Parameters
- $tag
string $tag the tag name
- $htmlOptions
array $htmlOptions the element attributes. The values will be HTML-encoded using
CHtml::encode() . If an 'encode' attribute is given and its value is false, the
rest of the attribute values will NOT be HTML-encoded. Since version 1.1.5,
attributes whose value is null will not be rendered.
- $content
mixed $content the content to be enclosed between open and close element tags. It will
not be HTML-encoded. If false, it means there is no body content.
- $closeTag
boolean $closeTag whether to generate the close tag.
Returns
string the generated HTML element tag
|
public static
string
|
#
openTag( string $tag, array $htmlOptions = array() )
Generates an open HTML element.
Generates an open HTML element.
Parameters
- $tag
string $tag the tag name
- $htmlOptions
array $htmlOptions the element attributes. The values will be HTML-encoded using
CHtml::encode() . If an 'encode' attribute is given and its value is false, the
rest of the attribute values will NOT be HTML-encoded. Since version 1.1.5,
attributes whose value is null will not be rendered.
Returns
string the generated HTML element tag
|
public static
string
|
#
closeTag( string $tag )
Generates a close HTML element.
Generates a close HTML element.
Parameters
- $tag
string $tag the tag name
Returns
string the generated HTML element tag
|
public static
string
|
#
cdata( string $text )
Encloses the given string within a CDATA tag.
Encloses the given string within a CDATA tag.
Parameters
- $text
string $text the string to be enclosed
Returns
string the CDATA tag with the enclosed content.
|
public static
string
|
#
metaTag( string $content, string $name = null, string $httpEquiv = null, array $options = array() )
Generates a meta tag that can be inserted in the head section of HTML
page.
Generates a meta tag that can be inserted in the head section of HTML
page.
Parameters
- $content
string $content content attribute of the meta tag
- $name
string $name name attribute of the meta tag. If null, the attribute will not be
generated
- $httpEquiv
string $httpEquiv http-equiv attribute of the meta tag. If null, the attribute will not
be generated
- $options
array $options other options in name-value pairs (e.g. 'scheme', 'lang')
Returns
string the generated meta tag
|
public static
string
|
#
linkTag( string $relation = null, string $type = null, string $href = null, string $media = null, array $options = array() )
Generates a link tag that can be inserted in the head section of HTML page.
Do not confuse this method with CHtml::link() . The latter generates a
hyperlink.
Generates a link tag that can be inserted in the head section of HTML page.
Do not confuse this method with CHtml::link() . The latter generates a
hyperlink.
Parameters
- $relation
string $relation rel attribute of the link tag. If null, the attribute will not be
generated.
- $type
string $type type attribute of the link tag. If null, the attribute will not be
generated.
- $href
string $href href attribute of the link tag. If null, the attribute will not be
generated.
- $media
string $media media attribute of the link tag. If null, the attribute will not be
generated.
- $options
array $options other options in name-value pairs
Returns
string the generated link tag
|
public static
string
|
#
css( string $text, string $media = '' )
Encloses the given CSS content with a CSS tag.
Encloses the given CSS content with a CSS tag.
Parameters
- $text
string $text the CSS content
- $media
string $media the media that this CSS should apply to.
Returns
string the CSS properly enclosed
|
public static
|
#
refresh( integer $seconds, string $url = '' )
Registers a 'refresh' meta tag. This method can be invoked anywhere in a
view. It will register a 'refresh' meta tag with CClientScript so that
the page can be refreshed in the specified seconds.
Registers a 'refresh' meta tag. This method can be invoked anywhere in a
view. It will register a 'refresh' meta tag with CClientScript so that
the page can be refreshed in the specified seconds.
Parameters
- $seconds
integer $seconds the number of seconds to wait before refreshing the page
- $url
string $url the URL to which the page should be redirected to. If empty, it means the
current page.
Since
1.1.1
|
public static
string
|
#
cssFile( string $url, string $media = '' )
Links to the specified CSS file.
Links to the specified CSS file.
Parameters
- $url
string $url the CSS URL
- $media
string $media the media that this CSS should apply to.
Returns
string the CSS link.
|
public static
string
|
#
script( string $text, array $htmlOptions = array() )
Encloses the given JavaScript within a script tag.
Encloses the given JavaScript within a script tag.
Parameters
- $text
string $text the JavaScript to be enclosed
- $htmlOptions
array $htmlOptions additional HTML attributes (see CHtml::tag() )
Returns
string the enclosed JavaScript
|
public static
string
|
#
scriptFile( string $url, array $htmlOptions = array() )
Includes a JavaScript file.
Includes a JavaScript file.
Parameters
- $url
string $url URL for the JavaScript file
- $htmlOptions
array $htmlOptions additional HTML attributes (see CHtml::tag() )
Returns
string the JavaScript file tag
|
public static
string
|
#
form( mixed $action = '', string $method = 'post', array $htmlOptions = array() )
Generates an opening form tag. This is a shortcut to CHtml::beginForm() .
Parameters
- $action
mixed $action the form action URL (see CHtml::normalizeUrl() for details about this
parameter.)
- $method
string $method form method (e.g. post, get)
- $htmlOptions
array $htmlOptions additional HTML attributes (see CHtml::tag() ).
Returns
string the generated form tag.
|
public static
string
|
#
beginForm( mixed $action = '', string $method = 'post', array $htmlOptions = array() )
Generates an opening form tag. Note, only the open tag is generated. A close
tag should be placed manually at the end of the form.
Generates an opening form tag. Note, only the open tag is generated. A close
tag should be placed manually at the end of the form.
Parameters
- $action
mixed $action the form action URL (see CHtml::normalizeUrl() for details about this
parameter.)
- $method
string $method form method (e.g. post, get)
- $htmlOptions
array $htmlOptions additional HTML attributes (see CHtml::tag() ).
Returns
string the generated form tag.
See
|
public static
string
|
#
endForm( )
Generates a closing form tag.
Generates a closing form tag.
Returns
string the generated tag
See
|
public static
string
|
#
statefulForm( mixed $action = '', string $method = 'post', array $htmlOptions = array() )
Generates a stateful form tag. A stateful form tag is similar to CHtml::form()
except that it renders an additional hidden field for storing persistent page
states. You should use this method to generate a form tag if you want to access
persistent page states when the form is submitted.
Generates a stateful form tag. A stateful form tag is similar to CHtml::form()
except that it renders an additional hidden field for storing persistent page
states. You should use this method to generate a form tag if you want to access
persistent page states when the form is submitted.
Parameters
- $action
mixed $action the form action URL (see CHtml::normalizeUrl() for details about this
parameter.)
- $method
string $method form method (e.g. post, get)
- $htmlOptions
array $htmlOptions additional HTML attributes (see CHtml::tag() ).
Returns
string the generated form tag.
|
public static
string
|
#
pageStateField( string $value )
Generates a hidden field for storing persistent page states. This method is
internally used by CHtml::statefulForm() .
Generates a hidden field for storing persistent page states. This method is
internally used by CHtml::statefulForm() .
Parameters
- $value
string $value the persistent page states in serialized format
Returns
string the generated hidden field
|
public static
string
|
#
link( string $text, mixed $url = '#', array $htmlOptions = array() )
Generates a hyperlink tag.
Generates a hyperlink tag.
Parameters
- $text
string $text link body. It will NOT be HTML-encoded. Therefore you can pass in HTML
code such as an image tag.
- $url
mixed $url a URL or an action route that can be used to create a URL. See CHtml::normalizeUrl() for more details about how to specify this parameter.
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated hyperlink
See
|
public static
string
|
#
mailto( string $text, string $email = '', array $htmlOptions = array() )
Generates a mailto link.
Parameters
- $text
string $text link body. It will NOT be HTML-encoded. Therefore you can pass in HTML
code such as an image tag.
- $email
string $email email address. If this is empty, the first parameter (link body) will be
treated as the email address.
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated mailto link
See
|
public static
string
|
#
image( string $src, string $alt = '', array $htmlOptions = array() )
Generates an image tag.
Parameters
- $src
string $src the image URL
- $alt
string $alt the alternative text display
- $htmlOptions
array $htmlOptions additional HTML attributes (see CHtml::tag() ).
Returns
string the generated image tag
|
public static
string
|
#
button( string $label = 'button', array $htmlOptions = array() )
Generates a button.
Parameters
- $label
string $label the button label
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated button tag
See
|
public static
string
|
#
htmlButton( string $label = 'button', array $htmlOptions = array() )
Generates a button using HTML button tag. This method is similar to CHtml::button() except that it generates a 'button' tag instead of 'input' tag.
Generates a button using HTML button tag. This method is similar to CHtml::button() except that it generates a 'button' tag instead of 'input' tag.
Parameters
- $label
string $label the button label. Note that this value will be directly inserted in the
button element without being HTML-encoded.
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated button tag
See
|
public static
string
|
#
submitButton( string $label = 'submit', array $htmlOptions = array() )
Generates a submit button.
Generates a submit button.
Parameters
- $label
string $label the button label
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated button tag
See
|
public static
string
|
#
resetButton( string $label = 'reset', array $htmlOptions = array() )
Generates a reset button.
Generates a reset button.
Parameters
- $label
string $label the button label
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated button tag
See
|
public static
string
|
#
imageButton( string $src, array $htmlOptions = array() )
Generates an image submit button.
Generates an image submit button.
Parameters
- $src
string $src the image URL
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated button tag
See
|
public static
string
|
#
linkButton( string $label = 'submit', array $htmlOptions = array() )
Generates a link submit button.
Generates a link submit button.
Parameters
- $label
string $label the button label
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated button tag
See
|
public static
string
|
#
label( string $label, string $for, array $htmlOptions = array() )
Generates a label tag.
Parameters
- $label
string $label label text. Note, you should HTML-encode the text if needed.
- $for
string $for the ID of the HTML element that this label is associated with. If this is
false, the 'for' attribute for the label tag will not be rendered.
- $htmlOptions
array $htmlOptions additional HTML attributes. The following HTML option is
recognized:
Returns
string the generated label tag
|
public static
string
|
#
colorField( string $name, string $value = '', array $htmlOptions = array() )
Generates a color picker field input.
Generates a color picker field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.16
See
|
public static
string
|
#
textField( string $name, string $value = '', array $htmlOptions = array() )
Generates a text field input.
Generates a text field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
See
|
public static
string
|
#
searchField( string $name, string $value = '', array $htmlOptions = array() )
Generates a search field input.
Generates a search field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.16
See
|
public static
string
|
#
numberField( string $name, string $value = '', array $htmlOptions = array() )
Generates a number field input.
Generates a number field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.14
See
|
public static
string
|
#
rangeField( string $name, string $value = '', array $htmlOptions = array() )
Generates a range field input.
Generates a range field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.14
See
|
public static
string
|
#
dateField( string $name, string $value = '', array $htmlOptions = array() )
Generates a date field input.
Generates a date field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.14
See
|
public static
string
|
#
timeField( string $name, string $value = '', array $htmlOptions = array() )
Generates a time field input.
Generates a time field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.14
See
|
public static
string
|
#
dateTimeField( string $name, string $value = '', array $htmlOptions = array() )
Generates a datetime field input.
Generates a datetime field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.16
See
|
public static
string
|
#
dateTimeLocalField( string $name, string $value = '', array $htmlOptions = array() )
Generates a local datetime field input.
Generates a local datetime field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.16
See
|
public static
string
|
#
weekField( string $name, string $value = '', array $htmlOptions = array() )
Generates a week field input.
Generates a week field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.16
See
|
public static
string
|
#
emailField( string $name, string $value = '', array $htmlOptions = array() )
Generates an email field input.
Generates an email field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.14
See
|
public static
string
|
#
telField( string $name, string $value = '', array $htmlOptions = array() )
Generates a telephone field input.
Generates a telephone field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.14
See
|
public static
string
|
#
urlField( string $name, string $value = '', array $htmlOptions = array() )
Generates a URL field input.
Generates a URL field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.14
See
|
public static
string
|
#
hiddenField( string $name, string $value = '', array $htmlOptions = array() )
Generates a hidden input.
Generates a hidden input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes (see CHtml::tag() ).
Returns
string the generated input field
See
|
public static
string
|
#
passwordField( string $name, string $value = '', array $htmlOptions = array() )
Generates a password field input.
Generates a password field input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
See
|
public static
string
|
#
fileField( string $name, string $value = '', array $htmlOptions = array() )
Generates a file input. Note, you have to set the enclosing form's 'enctype'
attribute to be 'multipart/form-data'. After the form is submitted, the uploaded
file information can be obtained via $_FILES[$name] (see PHP documentation).
Generates a file input. Note, you have to set the enclosing form's 'enctype'
attribute to be 'multipart/form-data'. After the form is submitted, the uploaded
file information can be obtained via $_FILES[$name] (see PHP documentation).
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes (see CHtml::tag() ).
Returns
string the generated input field
See
|
public static
string
|
#
textArea( string $name, string $value = '', array $htmlOptions = array() )
Generates a text area input.
Generates a text area input.
Parameters
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated text area
See
|
public static
string
|
#
radioButton( string $name, boolean $checked = false, array $htmlOptions = array() )
Generates a radio button.
Generates a radio button.
Parameters
- $name
string $name the input name
- $checked
boolean $checked whether the radio button is checked
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.) Since version 1.1.2, a special option named 'uncheckValue' is
available that can be used to specify the value returned when the radio button
is not checked. When set, a hidden field is rendered so that when the radio
button is not checked, we can still obtain the posted uncheck value. If
'uncheckValue' is not set or set to NULL, the hidden field will not be rendered.
Returns
string the generated radio button
See
|
public static
string
|
#
checkBox( string $name, boolean $checked = false, array $htmlOptions = array() )
Generates a check box.
Parameters
- $name
string $name the input name
- $checked
boolean $checked whether the check box is checked
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.) Since version 1.1.2, a special option named 'uncheckValue' is
available that can be used to specify the value returned when the checkbox is
not checked. When set, a hidden field is rendered so that when the checkbox is
not checked, we can still obtain the posted uncheck value. If 'uncheckValue' is
not set or set to NULL, the hidden field will not be rendered.
Returns
string the generated check box
See
|
public static
string
|
#
dropDownList( string $name, string $select, array $data, array $htmlOptions = array() )
Generates a drop down list.
Generates a drop down list.
Parameters
- $name
string $name the input name
- $select
string $select the selected value
- $data
array $data data for generating the list options (value=>display). You may use
CHtml::listData() to generate this data. Please refer to CHtml::listOptions() on
how this data is used to generate the list options. Note, the values and labels
will be automatically HTML-encoded by this method.
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are recognized. See CHtml::clientChange() and CHtml::tag() for
more details. In addition, the following options are also supported specifically
for dropdown list:
- encode: boolean, specifies whether to encode the values. Defaults to
true.
- prompt: string, specifies the prompt text shown as the first list option.
Its value is empty. Note, the prompt text will NOT be HTML-encoded.
- empty: string, specifies the text corresponding to empty selection. Its
value is empty. The 'empty' option can also be an array of value-label pairs.
Each pair will be used to render a list option at the beginning. Note, the text
label will NOT be HTML-encoded.
- options: array, specifies additional attributes for each OPTION tag. The
array keys must be the option values, and the array values are the extra OPTION
tag attributes in the name-value pairs. For example, <pre> array(
'value1'=>array('disabled'=>true,'label'=>'value 1'),
'value2'=>array('label'=>'value 2'), ); </pre>
Since 1.1.13, a special option named 'unselectValue' is available. It can be
used to set the value that will be returned when no option is selected in
multiple mode. When set, a hidden field is rendered so that if no option is
selected in multiple mode, we can still obtain the posted unselect value. If
'unselectValue' is not set or set to NULL, the hidden field will not be
rendered.
Returns
string the generated drop down list
See
|
public static
string
|
#
listBox( string $name, mixed $select, array $data, array $htmlOptions = array() )
Generates a list box.
Parameters
- $name
string $name the input name
- $select
mixed $select the selected value(s). This can be either a string for single selection
or an array for multiple selections.
- $data
array $data data for generating the list options (value=>display) You may use
CHtml::listData() to generate this data. Please refer to CHtml::listOptions() on
how this data is used to generate the list options. Note, the values and labels
will be automatically HTML-encoded by this method.
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized. See CHtml::clientChange() and CHtml::tag()
for more details. In addition, the following options are also supported
specifically for list box:
- encode: boolean, specifies whether to encode the values. Defaults to
true.
- prompt: string, specifies the prompt text shown as the first list option.
Its value is empty. Note, the prompt text will NOT be HTML-encoded.
- empty: string, specifies the text corresponding to empty selection. Its
value is empty. The 'empty' option can also be an array of value-label pairs.
Each pair will be used to render a list option at the beginning. Note, the text
label will NOT be HTML-encoded.
- options: array, specifies additional attributes for each OPTION tag. The
array keys must be the option values, and the array values are the extra OPTION
tag attributes in the name-value pairs. For example, <pre> array(
'value1'=>array('disabled'=>true,'label'=>'value 1'),
'value2'=>array('label'=>'value 2'), ); </pre>
Returns
string the generated list box
See
|
public static
string
|
#
checkBoxList( string $name, mixed $select, array $data, array $htmlOptions = array() )
Generates a check box list. A check box list allows multiple selection, like
CHtml::listBox() . As a result, the corresponding POST value is an array.
Generates a check box list. A check box list allows multiple selection, like
CHtml::listBox() . As a result, the corresponding POST value is an array.
Parameters
- $name
string $name name of the check box list. You can use this name to retrieve the selected
value(s) once the form is submitted.
- $select
mixed $select selection of the check boxes. This can be either a string for single
selection or an array for multiple selections.
- $data
array $data value-label pairs used to generate the check box list. Note, the values
will be automatically HTML-encoded, while the labels will not.
- $htmlOptions
array $htmlOptions additional HTML options. The options will be applied to each
checkbox input. The following special options are recognized:
- template: string, specifies how each checkbox is rendered. Defaults to
"{input} {label}", where "{input}" will be replaced by the generated check box
input tag while "{label}" be replaced by the corresponding check box label,
{beginLabel} will be replaced by <label> with labelOptions, {labelTitle}
will be replaced by the corresponding check box label title and {endLabel} will
be replaced by </label>
- separator: string, specifies the string that separates the generated check
boxes.
- checkAll: string, specifies the label for the "check all" checkbox. If this
option is specified, a 'check all' checkbox will be displayed. Clicking on this
checkbox will cause all checkboxes checked or unchecked.
- checkAllLast: boolean, specifies whether the 'check all' checkbox should be
displayed at the end of the checkbox list. If this option is not set (default)
or is false, the 'check all' checkbox will be displayed at the beginning of the
checkbox list.
- labelOptions: array, specifies the additional HTML attributes to be rendered
for every label tag in the list.
- container: string, specifies the checkboxes enclosing tag. Defaults to
'span'. If the value is an empty string, no enclosing tag will be generated
- baseID: string, specifies the base ID prefix to be used for checkboxes in
the list. This option is available since version 1.1.13.
Returns
string the generated check box list
|
public static
string
|
#
radioButtonList( string $name, string $select, array $data, array $htmlOptions = array() )
Generates a radio button list. A radio button list is like a checkBoxList check box list, except that it only allows single selection.
Generates a radio button list. A radio button list is like a checkBoxList check box list, except that it only allows single selection.
Parameters
- $name
string $name name of the radio button list. You can use this name to retrieve the
selected value(s) once the form is submitted.
- $select
string $select selection of the radio buttons.
- $data
array $data value-label pairs used to generate the radio button list. Note, the values
will be automatically HTML-encoded, while the labels will not.
- $htmlOptions
array $htmlOptions additional HTML options. The options will be applied to each radio
button input. The following special options are recognized:
- template: string, specifies how each radio button is rendered. Defaults to
"{input} {label}", where "{input}" will be replaced by the generated radio
button input tag while "{label}" will be replaced by the corresponding radio
button label, {beginLabel} will be replaced by <label> with labelOptions,
{labelTitle} will be replaced by the corresponding radio button label title and
{endLabel} will be replaced by </label>
- separator: string, specifies the string that separates the generated radio
buttons. Defaults to new line (
).
- labelOptions: array, specifies the additional HTML attributes to be rendered
for every label tag in the list.
- container: string, specifies the radio buttons enclosing tag. Defaults to
'span'. If the value is an empty string, no enclosing tag will be generated
- baseID: string, specifies the base ID prefix to be used for radio buttons in
the list. This option is available since version 1.1.13.
- empty: string, specifies the text corresponding to empty selection. Its
value is empty. The 'empty' option can also be an array of value-label pairs.
Each pair will be used to render a radio button at the beginning. Note, the text
label will NOT be HTML-encoded. This option is available since version
1.1.14.
Returns
string the generated radio button list
|
public static
string
|
#
ajaxLink( string $text, mixed $url, array $ajaxOptions = array(), array $htmlOptions = array() )
Generates a link that can initiate AJAX requests.
Generates a link that can initiate AJAX requests.
Parameters
- $text
string $text the link body (it will NOT be HTML-encoded.)
- $url
mixed $url the URL for the AJAX request. If empty, it is assumed to be the current
URL. See CHtml::normalizeUrl() for more details.
- $ajaxOptions
array $ajaxOptions AJAX options (see CHtml::ajax() )
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated link
See
|
public static
string
|
#
ajaxButton( string $label, mixed $url, array $ajaxOptions = array(), array $htmlOptions = array() )
Generates a push button that can initiate AJAX requests.
Generates a push button that can initiate AJAX requests.
Parameters
- $label
string $label the button label
- $url
mixed $url the URL for the AJAX request. If empty, it is assumed to be the current
URL. See CHtml::normalizeUrl() for more details.
- $ajaxOptions
array $ajaxOptions AJAX options (see CHtml::ajax() )
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated button
|
public static
string
|
#
ajaxSubmitButton( string $label, mixed $url, array $ajaxOptions = array(), array $htmlOptions = array() )
Generates a push button that can submit the current form in POST method.
Generates a push button that can submit the current form in POST method.
Parameters
- $label
string $label the button label
- $url
mixed $url the URL for the AJAX request. If empty, it is assumed to be the current
URL. See CHtml::normalizeUrl() for more details.
- $ajaxOptions
array $ajaxOptions AJAX options (see CHtml::ajax() )
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated button
|
public static
string
|
#
ajax( array $options )
Generates the JavaScript that initiates an AJAX request.
Generates the JavaScript that initiates an AJAX request.
Parameters
- $options
array $options AJAX options. The valid options are used in the form of
jQuery.ajax([settings]) as specified in the jQuery AJAX documentation. The
following special options are added for convenience:
- update: string, specifies the selector whose HTML content should be replaced
by the AJAX request result.
- replace: string, specifies the selector whose target should be replaced by
the AJAX request result.
Note, if you specify the 'success' option, the above options will be ignored.
Returns
string the generated JavaScript
See
|
public static
string
|
#
asset( string $path, boolean $hashByName = false )
Generates the URL for the published assets.
Generates the URL for the published assets.
Parameters
- $path
string $path the path of the asset to be published
- $hashByName
boolean $hashByName whether the published directory should be named as the hashed
basename. If false, the name will be the hashed dirname of the path being
published. Defaults to false. Set true if the path being published is shared
among different extensions.
Returns
string the asset URL
|
public static
string
|
#
normalizeUrl( mixed $url )
Normalizes the input parameter to be a valid URL.
Normalizes the input parameter to be a valid URL.
If the input parameter is an empty string, the currently requested URL will
be returned.
If the input parameter is a non-empty string, it is treated as a valid URL
and will be returned without any change.
If the input parameter is an array, it is treated as a controller route and a
list of GET parameters, and the CController::createUrl() method will be
invoked to create a URL. In this case, the first array element refers to the
controller route, and the rest key-value pairs refer to the additional GET
parameters for the URL. For example, <span
class="php-keyword1">array</span>(<span
class="php-quote">'post/list'</span>, <span
class="php-quote">'page'</span>=><span
class="php-num">3</span>) may be used to generate the URL
/index.php?r=post/<span
class="php-keyword1">list</span>&page=<span
class="php-num">3</span> .
Parameters
- $url
mixed $url the parameter to be used to generate a valid URL
Returns
string the normalized URL
|
protected static
string
|
#
inputField( string $type, string $name, string $value, array $htmlOptions )
Generates an input HTML tag. This method generates an input HTML tag based on
the given input name and value.
Generates an input HTML tag. This method generates an input HTML tag based on
the given input name and value.
Parameters
- $type
string $type the input type (e.g. 'text', 'radio')
- $name
string $name the input name
- $value
string $value the input value
- $htmlOptions
array $htmlOptions additional HTML attributes for the HTML tag (see CHtml::tag() ).
Returns
string the generated input tag
|
public static
string
|
#
activeLabel( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a label tag for a model attribute. The label text is the attribute
label and the label is associated with the input for the attribute (see CModel::getAttributeLabel() . If the attribute has input error, the label's CSS
class will be appended with CHtml::$errorCss .
Generates a label tag for a model attribute. The label text is the attribute
label and the label is associated with the input for the attribute (see CModel::getAttributeLabel() . If the attribute has input error, the label's CSS
class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. The following special options are
recognized:
- required: if this is set and is true, the label will be styled with CSS
class 'required' (customizable with CHtml::$requiredCss), and be decorated with
CHtml::$beforeRequiredLabel and CHtml::$afterRequiredLabel .
- label: this specifies the label to be displayed. If this is not set,
CModel::getAttributeLabel() will be called to get the label for display. If the
label is specified as false, no label will be rendered.
Returns
string the generated label tag
|
public static
string
|
|
public static
string
|
#
activeTextField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a text field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a text field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
See
|
public static
string
|
#
activeSearchField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a search field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a search field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.14
See
|
public static
string
|
#
activeUrlField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a url field input for a model attribute. If the attribute has input
error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a url field input for a model attribute. If the attribute has input
error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.11
See
|
public static
string
|
#
activeEmailField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates an email field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates an email field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.11
See
|
public static
string
|
#
activeNumberField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a number field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a number field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.11
See
|
public static
string
|
#
activeRangeField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a range field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a range field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.11
See
|
public static
string
|
#
activeDateField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a date field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a date field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.11
See
|
public static
string
|
#
activeTimeField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a time field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a time field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.14
See
|
public static
string
|
#
activeDateTimeField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a datetime field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a datetime field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.16
See
|
public static
string
|
#
activeDateTimeLocalField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a datetime-local field input for a model attribute. If the
attribute has input error, the input field's CSS class will be appended with
CHtml::$errorCss .
Generates a datetime-local field input for a model attribute. If the
attribute has input error, the input field's CSS class will be appended with
CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.16
See
|
public static
string
|
#
activeWeekField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a week field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a week field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.16
See
|
public static
string
|
#
activeColorField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a color picker field input for a model attribute. If the attribute
has input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a color picker field input for a model attribute. If the attribute
has input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.16
See
|
public static
string
|
#
activeTelField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a telephone field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a telephone field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
Since
1.1.14
See
|
public static
string
|
#
activeHiddenField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a hidden input for a model attribute.
Generates a hidden input for a model attribute.
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes.
Returns
string the generated input field
See
|
public static
string
|
#
activePasswordField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a password field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a password field input for a model attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated input field
See
|
public static
string
|
#
activeTextArea( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a text area input for a model attribute. If the attribute has input
error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a text area input for a model attribute. If the attribute has input
error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.)
Returns
string the generated text area
See
|
public static
string
|
#
activeFileField( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a file input for a model attribute. Note, you have to set the
enclosing form's 'enctype' attribute to be 'multipart/form-data'. After the form
is submitted, the uploaded file information can be obtained via $_FILES (see PHP
documentation).
Generates a file input for a model attribute. Note, you have to set the
enclosing form's 'enctype' attribute to be 'multipart/form-data'. After the form
is submitted, the uploaded file information can be obtained via $_FILES (see PHP
documentation).
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes (see CHtml::tag() ).
Returns
string the generated input field
See
|
public static
string
|
#
activeRadioButton( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a radio button for a model attribute. If the attribute has input
error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a radio button for a model attribute. If the attribute has input
error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.) A special option named 'uncheckValue' is available that can
be used to specify the value returned when the radio button is not checked. By
default, this value is '0'. Internally, a hidden field is rendered so that when
the radio button is not checked, we can still obtain the posted uncheck value.
If 'uncheckValue' is set as NULL, the hidden field will not be rendered.
Returns
string the generated radio button
See
|
public static
string
|
#
activeCheckBox( CModel $model, string $attribute, array $htmlOptions = array() )
Generates a check box for a model attribute. The attribute is assumed to take
either true or false value. If the attribute has input error, the input field's
CSS class will be appended with CHtml::$errorCss .
Generates a check box for a model attribute. The attribute is assumed to take
either true or false value. If the attribute has input error, the input field's
CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are also recognized (see CHtml::clientChange() and CHtml::tag()
for more details.) A special option named 'uncheckValue' is available that can
be used to specify the value returned when the checkbox is not checked. By
default, this value is '0'. Internally, a hidden field is rendered so that when
the checkbox is not checked, we can still obtain the posted uncheck value. If
'uncheckValue' is set as NULL, the hidden field will not be rendered.
Returns
string the generated check box
See
|
public static
string
|
#
activeDropDownList( CModel $model, string $attribute, array $data, array $htmlOptions = array() )
Generates a drop down list for a model attribute. If the attribute has input
error, the input field's CSS class will be appended with CHtml::$errorCss .
Generates a drop down list for a model attribute. If the attribute has input
error, the input field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $data
array $data data for generating the list options (value=>display) You may use
CHtml::listData() to generate this data. Please refer to CHtml::listOptions() on
how this data is used to generate the list options. Note, the values and labels
will be automatically HTML-encoded by this method.
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are recognized. See CHtml::clientChange() and CHtml::tag() for
more details. In addition, the following options are also supported:
- encode: boolean, specifies whether to encode the values. Defaults to
true.
- prompt: string, specifies the prompt text shown as the first list option.
Its value is empty. Note, the prompt text will NOT be HTML-encoded.
- empty: string, specifies the text corresponding to empty selection. Its
value is empty. The 'empty' option can also be an array of value-label pairs.
Each pair will be used to render a list option at the beginning. Note, the text
label will NOT be HTML-encoded.
- options: array, specifies additional attributes for each OPTION tag. The
array keys must be the option values, and the array values are the extra OPTION
tag attributes in the name-value pairs. For example, <pre> array(
'value1'=>array('disabled'=>true,'label'=>'value 1'),
'value2'=>array('label'=>'value 2'), ); </pre>
Since 1.1.13, a special option named 'unselectValue' is available. It can be
used to set the value that will be returned when no option is selected in
multiple mode. When set, a hidden field is rendered so that if no option is
selected in multiple mode, we can still obtain the posted unselect value. If
'unselectValue' is not set or set to NULL, the hidden field will not be
rendered.
Returns
string the generated drop down list
See
|
public static
string
|
#
activeListBox( CModel $model, string $attribute, array $data, array $htmlOptions = array() )
Generates a list box for a model attribute. The model attribute value is used
as the selection. If the attribute has input error, the input field's CSS class
will be appended with CHtml::$errorCss .
Generates a list box for a model attribute. The model attribute value is used
as the selection. If the attribute has input error, the input field's CSS class
will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $data
array $data data for generating the list options (value=>display) You may use
CHtml::listData() to generate this data. Please refer to CHtml::listOptions() on
how this data is used to generate the list options. Note, the values and labels
will be automatically HTML-encoded by this method.
- $htmlOptions
array $htmlOptions additional HTML attributes. Besides normal HTML attributes, a few
special attributes are recognized. See CHtml::clientChange() and CHtml::tag() for
more details. In addition, the following options are also supported:
- encode: boolean, specifies whether to encode the values. Defaults to
true.
- prompt: string, specifies the prompt text shown as the first list option.
Its value is empty. Note, the prompt text will NOT be HTML-encoded.
- empty: string, specifies the text corresponding to empty selection. Its
value is empty. The 'empty' option can also be an array of value-label pairs.
Each pair will be used to render a list option at the beginning. Note, the text
label will NOT be HTML-encoded.
- options: array, specifies additional attributes for each OPTION tag. The
array keys must be the option values, and the array values are the extra OPTION
tag attributes in the name-value pairs. For example, <pre> array(
'value1'=>array('disabled'=>true,'label'=>'value 1'),
'value2'=>array('label'=>'value 2'), ); </pre>
Returns
string the generated list box
See
|
public static
string
|
#
activeCheckBoxList( CModel $model, string $attribute, array $data, array $htmlOptions = array() )
Generates a check box list for a model attribute. The model attribute value
is used as the selection. If the attribute has input error, the input field's
CSS class will be appended with CHtml::$errorCss . Note that a check box list
allows multiple selection, like CHtml::listBox() . As a result, the corresponding
POST value is an array. In case no selection is made, the corresponding POST
value is an empty string.
Generates a check box list for a model attribute. The model attribute value
is used as the selection. If the attribute has input error, the input field's
CSS class will be appended with CHtml::$errorCss . Note that a check box list
allows multiple selection, like CHtml::listBox() . As a result, the corresponding
POST value is an array. In case no selection is made, the corresponding POST
value is an empty string.
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $data
array $data value-label pairs used to generate the check box list. Note, the values
will be automatically HTML-encoded, while the labels will not.
- $htmlOptions
array $htmlOptions additional HTML options. The options will be applied to each
checkbox input. The following special options are recognized:
- template: string, specifies how each checkbox is rendered. Defaults to
"{input} {label}", where "{input}" will be replaced by the generated check box
input tag while "{label}" will be replaced by the corresponding check box
label.
- separator: string, specifies the string that separates the generated check
boxes.
- checkAll: string, specifies the label for the "check all" checkbox. If this
option is specified, a 'check all' checkbox will be displayed. Clicking on this
checkbox will cause all checkboxes checked or unchecked.
- checkAllLast: boolean, specifies whether the 'check all' checkbox should be
displayed at the end of the checkbox list. If this option is not set (default)
or is false, the 'check all' checkbox will be displayed at the beginning of the
checkbox list.
- encode: boolean, specifies whether to encode HTML-encode tag attributes and
values. Defaults to true.
- labelOptions: array, specifies the additional HTML attributes to be rendered
for every label tag in the list.
- container: string, specifies the checkboxes enclosing tag. Defaults to
'span'. If the value is an empty string, no enclosing tag will be generated
- baseID: string, specifies the base ID prefix to be used for checkboxes in
the list. This option is available since version 1.1.13.
Since 1.1.7, a special option named 'uncheckValue' is available. It can be used
to set the value that will be returned when the checkbox is not checked. By
default, this value is ''. Internally, a hidden field is rendered so when the
checkbox is not checked, we can still obtain the value. If 'uncheckValue' is set
to NULL, there will be no hidden field rendered.
Returns
string the generated check box list
See
|
public static
string
|
#
activeRadioButtonList( CModel $model, string $attribute, array $data, array $htmlOptions = array() )
Generates a radio button list for a model attribute. The model attribute
value is used as the selection. If the attribute has input error, the input
field's CSS class will be appended with CHtml::$errorCss .
Generates a radio button list for a model attribute. The model attribute
value is used as the selection. If the attribute has input error, the input
field's CSS class will be appended with CHtml::$errorCss .
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $data
array $data value-label pairs used to generate the radio button list. Note, the values
will be automatically HTML-encoded, while the labels will not.
- $htmlOptions
array $htmlOptions additional HTML options. The options will be applied to each radio
button input. The following special options are recognized:
- template: string, specifies how each radio button is rendered. Defaults to
"{input} {label}", where "{input}" will be replaced by the generated radio
button input tag while "{label}" will be replaced by the corresponding radio
button label, {beginLabel} will be replaced by <label> with labelOptions,
{labelTitle} will be replaced by the corresponding radio button label title and
{endLabel} will be replaced by </label>
- separator: string, specifies the string that separates the generated radio
buttons. Defaults to new line (
).
- encode: boolean, specifies whether to encode HTML-encode tag attributes and
values. Defaults to true.
- labelOptions: array, specifies the additional HTML attributes to be rendered
for every label tag in the list.
- container: string, specifies the radio buttons enclosing tag. Defaults to
'span'. If the value is an empty string, no enclosing tag will be generated
- baseID: string, specifies the base ID prefix to be used for radio buttons in
the list. This option is available since version 1.1.13.
- empty: string, specifies the text corresponding to empty selection. Its
value is empty. The 'empty' option can also be an array of value-label pairs.
Each pair will be used to render a radio button at the beginning. Note, the text
label will NOT be HTML-encoded. This option is available since version
1.1.14.
Since version 1.1.7, a special option named 'uncheckValue' is available that
can be used to specify the value returned when the radio button is not checked.
By default, this value is ''. Internally, a hidden field is rendered so that
when the radio button is not checked, we can still obtain the posted uncheck
value. If 'uncheckValue' is set as NULL, the hidden field will not be rendered.
Returns
string the generated radio button list
See
|
public static
string
|
#
errorSummary( mixed $model, string $header = null, string $footer = null, array $htmlOptions = array() )
Displays a summary of validation errors for one or several models.
Displays a summary of validation errors for one or several models.
Parameters
- $model
mixed $model the models whose input errors are to be displayed. This can be either a
single model or an array of models.
- $header
string $header a piece of HTML code that appears in front of the errors
- $footer
string $footer a piece of HTML code that appears at the end of the errors
- $htmlOptions
array $htmlOptions additional HTML attributes to be rendered in the container div tag.
A special option named 'firstError' is recognized, which when set true, will
make the error summary to show only the first error message of each attribute.
If this is not set or is false, all error messages will be displayed. This
option has been available since version 1.1.3.
Returns
string the error summary. Empty if no errors are found.
See
|
public static
string
|
#
error( CModel $model, string $attribute, array $htmlOptions = array() )
Displays the first validation error for a model attribute.
Displays the first validation error for a model attribute.
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute name
- $htmlOptions
array $htmlOptions additional HTML attributes to be rendered in the container tag.
Returns
string the error display. Empty if no errors are found.
See
|
public static
array
|
#
listData( array $models, mixed $valueField, mixed $textField, mixed $groupField = '' )
Generates the data suitable for list-based HTML elements. The generated data
can be used in CHtml::dropDownList() , CHtml::listBox() , CHtml::checkBoxList() ,
CHtml::radioButtonList() , and their active-versions (such as CHtml::activeDropDownList() ). Note, this method does not HTML-encode the generated data.
You may call CHtml::encodeArray() to encode it if needed. Please refer to the
CHtml::value() method on how to specify value field, text field and group field.
You can also pass anonymous functions as second, third and fourth arguments
which calculates text field value (PHP 5.3+ only) since 1.1.13. Your anonymous
function should receive one argument, which is the model, the current
<option> tag is generated from.
Generates the data suitable for list-based HTML elements. The generated data
can be used in CHtml::dropDownList() , CHtml::listBox() , CHtml::checkBoxList() ,
CHtml::radioButtonList() , and their active-versions (such as CHtml::activeDropDownList() ). Note, this method does not HTML-encode the generated data.
You may call CHtml::encodeArray() to encode it if needed. Please refer to the
CHtml::value() method on how to specify value field, text field and group field.
You can also pass anonymous functions as second, third and fourth arguments
which calculates text field value (PHP 5.3+ only) since 1.1.13. Your anonymous
function should receive one argument, which is the model, the current
<option> tag is generated from.
CHtml::listData($posts,'id',function($post) {
return CHtml::encode($post->title);
});
Parameters
- $models
array $models a list of model objects. This parameter can also be an array of
associative arrays (e.g. results of CDbCommand::queryAll() ).
- $valueField
mixed $valueField the attribute name or anonymous function (PHP 5.3+) for list option
values
- $textField
mixed $textField the attribute name or anonymous function (PHP 5.3+) for list option
texts
- $groupField
mixed $groupField the attribute name or anonymous function (PHP 5.3+) for list option
group names. If empty, no group will be generated.
Returns
|
public static
mixed
|
#
value( mixed $model, mixed $attribute, mixed $defaultValue = null )
Evaluates the value of the specified attribute for the given model. The
attribute name can be given in a dot syntax. For example, if the attribute is
"author.firstName", this method will return the value of
"$model->author->firstName". A default value (passed as the last
parameter) will be returned if the attribute does not exist or is broken in the
middle (e.g. $model->author is null). The model can be either an object or an
array. If the latter, the attribute is treated as a key of the array. For the
example of "author.firstName", if would mean the array value
"$model['author']['firstName']".
Evaluates the value of the specified attribute for the given model. The
attribute name can be given in a dot syntax. For example, if the attribute is
"author.firstName", this method will return the value of
"$model->author->firstName". A default value (passed as the last
parameter) will be returned if the attribute does not exist or is broken in the
middle (e.g. $model->author is null). The model can be either an object or an
array. If the latter, the attribute is treated as a key of the array. For the
example of "author.firstName", if would mean the array value
"$model['author']['firstName']".
Anonymous function could also be used for attribute calculation since 1.1.13
($attribute parameter; PHP 5.3+ only) as follows:
$taskClosedSecondsAgo=CHtml::value($closedTask,function($model) {
return time()-$model->closed_at;
});
Your anonymous function should receive one argument, which is the model, the
current value is calculated from. This feature could be used together with the
CHtml::listData() . Please refer to its documentation for more details.
Parameters
- $model
mixed $model the model. This can be either an object or an array.
- $attribute
mixed $attribute the attribute name (use dot to concatenate multiple attributes) or
anonymous function (PHP 5.3+). Remember that functions created by
"create_function" are not supported by this method. Also note that numeric value
is meaningless when first parameter is object typed.
- $defaultValue
mixed $defaultValue the default value to return when the attribute does not exist.
Returns
mixed the attribute value.
|
public static
string
|
#
getIdByName( string $name )
Generates a valid HTML ID based on name.
Generates a valid HTML ID based on name.
Parameters
- $name
string $name name from which to generate HTML ID
Returns
string the ID generated based on name.
|
public static
string
|
#
activeId( CModel $model, string $attribute )
Generates input field ID for a model attribute.
Generates input field ID for a model attribute.
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
Returns
string the generated input field ID
|
public static
string
|
#
modelName( CModel |string $model )
Generates HTML name for given model.
Generates HTML name for given model.
Parameters
- $model
CModel |string
$model the data model or the model class name
Returns
string the generated HTML name value
Since
1.1.14
See
|
public static
|
#
setModelNameConverter( callable|null $converter )
Set generator used in the CHtml::modelName() method. You can use the
null value to restore default generator.
Set generator used in the CHtml::modelName() method. You can use the
null value to restore default generator.
Parameters
- $converter
callable|null $converter the new generator, the model or class name will be passed to the this
callback and result must be a valid value for HTML name attribute.
Throws
Since
1.1.14
|
public static
string
|
#
activeName( CModel $model, string $attribute )
Generates input field name for a model attribute. Unlike CHtml::resolveName() ,
this method does NOT modify the attribute name.
Generates input field name for a model attribute. Unlike CHtml::resolveName() ,
this method does NOT modify the attribute name.
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
Returns
string the generated input field name
|
protected static
string
|
#
activeInputField( string $type, CModel $model, string $attribute, array $htmlOptions )
Generates an input HTML tag for a model attribute. This method generates an
input HTML tag based on the given data model and attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
This enables highlighting the incorrect input.
Generates an input HTML tag for a model attribute. This method generates an
input HTML tag based on the given data model and attribute. If the attribute has
input error, the input field's CSS class will be appended with CHtml::$errorCss .
This enables highlighting the incorrect input.
Parameters
- $type
string $type the input type (e.g. 'text', 'radio')
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions additional HTML attributes for the HTML tag
Returns
string the generated input tag
|
public static
string
|
#
listOptions( mixed $selection, array $listData, array & $htmlOptions )
Generates the list options.
Generates the list options.
Parameters
- $selection
mixed $selection the selected value(s). This can be either a string for single
selection or an array for multiple selections.
- $listData
array $listData the option data (see CHtml::listData() )
- $htmlOptions
array $htmlOptions additional HTML attributes. The following two special attributes
are recognized:
- encode: boolean, specifies whether to encode the values. Defaults to
true.
- prompt: string, specifies the prompt text shown as the first list option.
Its value is empty. Note, the prompt text will NOT be HTML-encoded.
- empty: string, specifies the text corresponding to empty selection. Its
value is empty. The 'empty' option can also be an array of value-label pairs.
Each pair will be used to render a list option at the beginning. Note, the text
label will NOT be HTML-encoded.
- options: array, specifies additional attributes for each OPTION tag. The
array keys must be the option values, and the array values are the extra OPTION
tag attributes in the name-value pairs. For example, <pre> array(
'value1'=>array('disabled'=>true,'label'=>'value 1'),
'value2'=>array('label'=>'value 2'), ); </pre>
- key: string, specifies the name of key attribute of the selection object(s).
This is used when the selection is represented in terms of objects. In this
case, the property named by the key option of the objects will be treated as the
actual selection value. This option defaults to 'primaryKey', meaning using the
'primaryKey' property value of the objects in the selection. This option has
been available since version 1.1.3.
Returns
string the generated list options
|
protected static
|
#
clientChange( string $event, array & $htmlOptions )
Generates the JavaScript with the specified client changes.
Generates the JavaScript with the specified client changes.
Parameters
- $event
string $event event name (without 'on')
- $htmlOptions
array $htmlOptions HTML attributes which may contain the following special attributes
specifying the client change behaviors:
- submit: string, specifies the URL to submit to. If the current element has a
parent form, that form will be submitted, and if 'submit' is non-empty its value
will replace the form's URL. If there is no parent form the data listed in
'params' will be submitted instead (via POST method), to the URL in 'submit' or
the currently requested URL if 'submit' is empty. Please note that if the 'csrf'
setting is true, the CSRF token will be included in the params too.
- params: array, name-value pairs that should be submitted together with the
form. This is only used when 'submit' option is specified.
- csrf: boolean, whether a CSRF token should be automatically included in
'params' when
CHttpRequest::$enableCsrfValidation is true. Defaults to
false. You may want to set this to be true if there is no enclosing form around
this element. This option is meaningful only when 'submit' option is set.
- return: boolean, the return value of the javascript. Defaults to false,
meaning that the execution of javascript would not cause the default behavior of
the event.
- confirm: string, specifies the message that should show in a pop-up
confirmation dialog.
- ajax: array, specifies the AJAX options (see
CHtml::ajax() ).
- live: boolean, whether the event handler should be delegated or directly
bound. If not set,
CHtml::$liveEvents will be used. This option has been
available since version 1.1.11.
This parameter has been available since version 1.1.1.
|
public static
|
#
resolveNameID( CModel $model, string & $attribute, array & $htmlOptions )
Generates input name and ID for a model attribute. This method will update
the HTML options by setting appropriate 'name' and 'id' attributes. This method
may also modify the attribute name if the name contains square brackets (mainly
used in tabular input).
Generates input name and ID for a model attribute. This method will update
the HTML options by setting appropriate 'name' and 'id' attributes. This method
may also modify the attribute name if the name contains square brackets (mainly
used in tabular input).
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
- $htmlOptions
array $htmlOptions the HTML options
|
public static
string
|
#
resolveName( CModel $model, string & $attribute )
Generates input name for a model attribute. Note, the attribute name may be
modified after calling this method if the name contains square brackets (mainly
used in tabular input) before the real attribute name.
Generates input name for a model attribute. Note, the attribute name may be
modified after calling this method if the name contains square brackets (mainly
used in tabular input) before the real attribute name.
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute
Returns
string the input name
|
public static
mixed
|
#
resolveValue( CModel $model, string $attribute )
Evaluates the attribute value of the model. This method can recognize the
attribute name written in array format. For example, if the attribute name is
'name[a][b]', the value "$model->name['a']['b']" will be returned.
Evaluates the attribute value of the model. This method can recognize the
attribute name written in array format. For example, if the attribute name is
'name[a][b]', the value "$model->name['a']['b']" will be returned.
Parameters
- $model
CModel
$model the data model
- $attribute
string $attribute the attribute name
Returns
mixed the attribute value
Since
1.1.3
|
protected static
|
#
addErrorCss( array & $htmlOptions )
Appends CHtml::$errorCss to the 'class' attribute.
Parameters
- $htmlOptions
array $htmlOptions HTML options to be modified
|
public static
string
|
#
renderAttributes( array $htmlOptions )
Renders the HTML tag attributes. Since version 1.1.5, attributes whose value
is null will not be rendered. Special attributes, such as 'checked', 'disabled',
'readonly', will be rendered properly based on their corresponding boolean
value.
Renders the HTML tag attributes. Since version 1.1.5, attributes whose value
is null will not be rendered. Special attributes, such as 'checked', 'disabled',
'readonly', will be rendered properly based on their corresponding boolean
value.
Parameters
- $htmlOptions
array $htmlOptions attributes to be rendered
Returns
string the rendering result
|