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.
*
separator: string, specifies the string that separates the generated check boxes.
*
* @return string the generated check box list
*/
public static function checkBoxList($name,$select,$data,$htmlOptions=array())
{
$template=isset($htmlOptions['template'])?$htmlOptions['template']:'{input} {label}';
$separator=isset($htmlOptions['separator'])?$htmlOptions['separator']:" \n";
unset($htmlOptions['template'],$htmlOptions['separator']);
if(substr($name,-2)!=='[]')
$name.='[]';
$items=array();
$baseID=self::getIdByName($name);
$id=0;
foreach($data as $value=>$label)
{
$checked=!is_array($select) && !strcmp($value,$select) || is_array($select) && in_array($value,$select);
$htmlOptions['value']=$value;
$htmlOptions['id']=$baseID.'_'.$id++;
$option=self::checkBox($name,$checked,$htmlOptions);
$items[]=strtr($template,array('{input}'=>$option,'{label}'=>$label));
}
return implode($separator,$items);
}
/**
* Generates a radio button list.
* A radio button list is like a {@link checkBoxList check box list}, except that
* it only allows single selection.
* @param string name of the radio button list. You can use this name to retrieve
* the selected value(s) once the form is submitted.
* @param mixed selection of the radio buttons. This can be either a string
* for single selection or an array for multiple selections.
* @param array value-label pairs used to generate the radio button list.
* @param array addtional 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
* radio button input tag while "{label}" be replaced by the corresponding radio button label.
*
separator: string, specifies the string that separates the generated radio buttons.
*
* @return string the generated radio button list
*/
public static function radioButtonList($name,$select,$data,$htmlOptions=array())
{
$template=isset($htmlOptions['template'])?$htmlOptions['template']:'{input} {label}';
$separator=isset($htmlOptions['separator'])?$htmlOptions['separator']:" \n";
unset($htmlOptions['template'],$htmlOptions['separator']);
$items=array();
$baseID=self::getIdByName($name);
$id=0;
foreach($data as $value=>$label)
{
$checked=!strcmp($value,$select);
$htmlOptions['value']=$value;
$htmlOptions['id']=$baseID.'_'.$id++;
$option=self::radioButton($name,$checked,$htmlOptions);
$items[]=strtr($template,array('{input}'=>$option,'{label}'=>$label));
}
return implode($separator,$items);
}
/**
* Generates a link that can initiate AJAX requests.
* @param string the link body (it will NOT be HTML-encoded.)
* @param string the URL for the AJAX request. If empty, it is assumed to be the current URL. See {@link normalizeUrl} for more details.
* @param array AJAX options (see {@link ajax})
* @param array additional HTML attributes. Besides normal HTML attributes, a few special
* attributes are also recognized (see {@link clientChange} for more details.)
* @return string the generated link
* @see normalizeUrl
* @see ajax
*/
public static function ajaxLink($text,$url,$ajaxOptions=array(),$htmlOptions=array())
{
if(!isset($htmlOptions['href']))
$htmlOptions['href']='#';
$ajaxOptions['url']=$url;
$htmlOptions['ajax']=$ajaxOptions;
self::clientChange('click',$htmlOptions);
return self::tag('a',$htmlOptions,$text);
}
/**
* Generates a push button that can initiate AJAX requests.
* @param string the button label
* @param string the URL for the AJAX request. If empty, it is assumed to be the current URL. See {@link normalizeUrl} for more details.
* @param array AJAX options (see {@link ajax})
* @param array additional HTML attributes. Besides normal HTML attributes, a few special
* attributes are also recognized (see {@link clientChange} for more details.)
* @return string the generated button
*/
public static function ajaxButton($label,$url,$ajaxOptions=array(),$htmlOptions=array())
{
$ajaxOptions['url']=$url;
$htmlOptions['ajax']=$ajaxOptions;
return self::button($label,$htmlOptions);
}
/**
* Generates a push button that can submit the current form in POST method.
* @param string the button label
* @param string the URL for the AJAX request. If empty, it is assumed to be the current URL. See {@link normalizeUrl} for more details.
* @param array AJAX options (see {@link ajax})
* @param array additional HTML attributes. Besides normal HTML attributes, a few special
* attributes are also recognized (see {@link clientChange} for more details.)
* @return string the generated button
*/
public static function ajaxSubmitButton($label,$url,$ajaxOptions=array(),$htmlOptions=array())
{
$ajaxOptions['type']='POST';
return self::ajaxButton($label,$url,$ajaxOptions,$htmlOptions);
}
/**
* Generates the JavaScript that initiates an AJAX request.
* @param array AJAX options. The valid options are 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.
* @return string the generated JavaScript
* @see http://docs.jquery.com/Ajax/jQuery.ajax#options
*/
public static function ajax($options)
{
Yii::app()->getClientScript()->registerCoreScript('jquery');
if(!isset($options['url']))
$options['url']='js:location.href';
else
$options['url']=self::normalizeUrl($options['url']);
if(!isset($options['cache']))
$options['cache']=false;
if(!isset($options['data']) && isset($options['type']))
$options['data']='js:jQuery(this).parents("form").serialize()';
foreach(array('beforeSend','complete','error','success') as $name)
{
if(isset($options[$name]) && strpos($options[$name],'js:')!==0)
$options[$name]='js:'.$options[$name];
}
if(isset($options['update']))
{
if(!isset($options['success']))
$options['success']='js:function(html){jQuery("'.$options['update'].'").html(html)}';
unset($options['update']);
}
if(isset($options['replace']))
{
if(!isset($options['success']))
$options['success']='js:function(html){jQuery("'.$options['replace'].'").replaceWith(html)}';
unset($options['replace']);
}
return 'jQuery.ajax('.CJavaScript::encode($options).');';
}
/**
* Generates the URL for the published assets.
* @param string the path of the asset to be published
* @param boolean 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.
* @return string the asset URL
*/
public static function asset($path,$hashByName=false)
{
return Yii::app()->getAssetManager()->publish($path,$hashByName);
}
/**
* Generates the HTML code for including the specified core script.
* @param string core script name. The valid names are listed in framework/web/js/packages.php
* @return string the HTML code
*/
public static function coreScript($name)
{
return Yii::app()->getClientScript()->renderCoreScript($name);
}
/**
* Generates a URL if the input specifies the route to a controller action.
* @param mixed the URL to be normalized. If a string, the URL is returned back;
* if an array, it is considered as a route to a controller action and will
* be used to generate a URL using {@link CController::createUrl}; if the URL is empty,
* the currently requested URL is returned.
* @param string the URL
*/
public static function normalizeUrl($url)
{
if(is_array($url))
$url=isset($url[0]) ? Yii::app()->getController()->createUrl($url[0],array_splice($url,1)) : '';
return $url==='' ? Yii::app()->getRequest()->getUrl() : $url;
}
/**
* Generates an input HTML tag.
* This method generates an input HTML tag based on the given input name and value.
* @param string the input type (e.g. 'text', 'radio')
* @param string the input name
* @param string the input value
* @param array additional HTML attributes for the HTML tag
* @return string the generated input tag
*/
protected static function inputField($type,$name,$value,$htmlOptions)
{
$htmlOptions['type']=$type;
$htmlOptions['value']=$value;
$htmlOptions['name']=$name;
if(!isset($htmlOptions['id']))
$htmlOptions['id']=self::getIdByName($name);
return self::tag('input',$htmlOptions);
}
/**
* 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. If the attribute has input error,
* the label's CSS class will be appended with {@link errorCss}.
* @param CModel the data model
* @param string the attribute
* @param array additional HTML attributes.
* @return string the generated label tag
*/
public static function activeLabel($model,$attribute,$htmlOptions=array())
{
if(($pos=strpos($attribute,'['))!==false)
$name=get_class($model).substr($attribute,$pos).'['.($attribute=substr($attribute,0,$pos)).']';
else
$name=get_class($model).'['.$attribute.']';
$label=$model->getAttributeLabel($attribute);
$for=self::getIdByName($name);
if($model->hasErrors($attribute))
self::addErrorCss($htmlOptions);
return self::label($label,$for,$htmlOptions);
}
/**
* 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 {@link errorCss}.
* @param CModel the data model
* @param string the attribute
* @param array additional HTML attributes. Besides normal HTML attributes, a few special
* attributes are also recognized (see {@link clientChange} for more details.)
* @return string the generated input field
* @see clientChange
* @see activeInputField
*/
public static function activeTextField($model,$attribute,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
self::clientChange('change',$htmlOptions);
return self::activeInputField('text',$model,$attribute,$htmlOptions);
}
/**
* Generates a hidden input for a model attribute.
* @param CModel the data model
* @param string the attribute
* @param array additional HTML attributes.
* @return string the generated input field
* @see activeInputField
*/
public static function activeHiddenField($model,$attribute,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
return self::activeInputField('hidden',$model,$attribute,$htmlOptions);
}
/**
* 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 {@link errorCss}.
* @param CModel the data model
* @param string the attribute
* @param array additional HTML attributes. Besides normal HTML attributes, a few special
* attributes are also recognized (see {@link clientChange} for more details.)
* @return string the generated input field
* @see clientChange
* @see activeInputField
*/
public static function activePasswordField($model,$attribute,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
self::clientChange('change',$htmlOptions);
return self::activeInputField('password',$model,$attribute,$htmlOptions);
}
/**
* 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 {@link errorCss}.
* @param CModel the data model
* @param string the attribute
* @param array additional HTML attributes. Besides normal HTML attributes, a few special
* attributes are also recognized (see {@link clientChange} for more details.)
* @return string the generated text area
* @see clientChange
*/
public static function activeTextArea($model,$attribute,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
self::clientChange('change',$htmlOptions);
if($model->hasErrors($attribute))
self::addErrorCss($htmlOptions);
return self::tag('textarea',$htmlOptions,self::encode($model->$attribute));
}
/**
* 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).
* @param CModel the data model
* @param string the attribute
* @param array additional HTML attributes.
* @return string the generated input field
* @see activeInputField
*/
public static function activeFileField($model,$attribute,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
return self::activeInputField('file',$model,$attribute,$htmlOptions);
}
/**
* Generates a radio button for a model attribute.
* If the attribute has input error, the input field's CSS class will
* be appended with {@link errorCss}.
* @param CModel the data model
* @param string the attribute
* @param array additional HTML attributes. Besides normal HTML attributes, a few special
* attributes are also recognized (see {@link clientChange} for more details.)
* @return string the generated radio button
* @see clientChange
* @see activeInputField
*/
public static function activeRadioButton($model,$attribute,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
if(!isset($htmlOptions['value']))
$htmlOptions['value']=1;
if($model->$attribute)
$htmlOptions['checked']='checked';
self::clientChange('click',$htmlOptions);
return self::hiddenField($htmlOptions['name'],$htmlOptions['value']?0:-1,array('id'=>self::ID_PREFIX.$htmlOptions['id']))
. self::activeInputField('radio',$model,$attribute,$htmlOptions);
}
/**
* 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 {@link errorCss}.
* @param CModel the data model
* @param string the attribute
* @param array additional HTML attributes. Besides normal HTML attributes, a few special
* attributes are also recognized (see {@link clientChange} for more details.)
* @return string the generated check box
* @see clientChange
* @see activeInputField
*/
public static function activeCheckBox($model,$attribute,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
if(!isset($htmlOptions['value']))
$htmlOptions['value']=1;
if($model->$attribute)
$htmlOptions['checked']='checked';
self::clientChange('click',$htmlOptions);
return self::hiddenField($htmlOptions['name'],'',array('id'=>self::ID_PREFIX.$htmlOptions['id']))
. self::activeInputField('checkbox',$model,$attribute,$htmlOptions);
}
/**
* 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 {@link errorCss}.
* @param CModel the data model
* @param string the attribute
* @param array data for generating the list options (value=>display)
* @param array additional HTML attributes. Besides normal HTML attributes, a few special
* attributes are also recognized (see {@link clientChange} for more details.)
* @return string the generated drop down list
* @see clientChange
* @see listData
*/
public static function activeDropDownList($model,$attribute,$data,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
$selection=$model->$attribute;
$options="\n".self::listOptions($selection,$data,$htmlOptions);
self::clientChange('change',$htmlOptions);
if($model->hasErrors($attribute))
self::addErrorCss($htmlOptions);
return self::tag('select',$htmlOptions,$options);
}
/**
* 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 {@link errorCss}.
* @param CModel the data model
* @param string the attribute
* @param array data for generating the list options (value=>display)
* @param array additional HTML attributes. Besides normal HTML attributes, a few special
* attributes are also recognized (see {@link clientChange} for more details.)
* @return string the generated list box
* @see clientChange
* @see listData
*/
public static function activeListBox($model,$attribute,$data,$htmlOptions=array())
{
if(!isset($htmlOptions['size']))
$htmlOptions['size']=4;
return self::activeDropDownList($model,$attribute,$data,$htmlOptions);
}
/**
* 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 {@link errorCss}.
* Note that a check box list allows multiple selection, like {@link listBox}.
* As a result, the corresponding POST value is an array.
* @param CModel the data model
* @param string the attribute
* @param array value-label pairs used to generate the check box list.
* @param array addtional 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.
*
separator: string, specifies the string that separates the generated check boxes.
*
* @return string the generated check box list
* @see checkBoxList
*/
public static function activeCheckBoxList($model,$attribute,$data,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
$selection=$model->$attribute;
if($model->hasErrors($attribute))
self::addErrorCss($htmlOptions);
$name=$htmlOptions['name'];
unset($htmlOptions['name'],$htmlOptions['id']);
return self::hiddenField($name,'',array('id'=>self::ID_PREFIX.$htmlOptions['id']))
. self::checkBoxList($name,$selection,$data,$htmlOptions);
}
/**
* 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 {@link errorCss}.
* @param CModel the data model
* @param string the attribute
* @param array value-label pairs used to generate the radio button list.
* @param array addtional 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
* radio button input tag while "{label}" be replaced by the corresponding radio button label.
*
separator: string, specifies the string that separates the generated radio buttons.
*
* @return string the generated radio button list
* @see radioButtonList
*/
public static function activeRadioButtonList($model,$attribute,$data,$htmlOptions=array())
{
self::resolveNameID($model,$attribute,$htmlOptions);
$selection=$model->$attribute;
if($model->hasErrors($attribute))
self::addErrorCss($htmlOptions);
$name=$htmlOptions['name'];
unset($htmlOptions['name'],$htmlOptions['id']);
return self::hiddenField($name,'',array('id'=>self::ID_PREFIX.$htmlOptions['id']))
. self::radioButtonList($name,$selection,$data,$htmlOptions);
}
/**
* Returns the element ID that is used by methods such as {@link activeTextField}.
* @param CModel the data model
* @param string the attribute
* @return string the element ID for the active field corresponding to the specified model and attribute.
*/
public static function getActiveId($model,$attribute)
{
return get_class($model).'_'.$attribute;
}
/**
* Displays a summary of validation errors for one or several models.
* @param mixed the models whose input errors are to be displayed. This can be either
* a single model or an array of models.
* @param string a piece of HTML code that appears in front of the errors
* @param string a piece of HTML code that appears at the end of the errors
* @return string the error summary. Empty if no errors are found.
* @see CModel::getErrors
* @see errorSummaryCss
*/
public static function errorSummary($model,$header='',$footer='')
{
if($header==='')
$header='
'.Yii::t('yii','Please fix the following input errors:').'
';
$content='';
if(!is_array($model))
$model=array($model);
foreach($model as $m)
{
foreach($m->getErrors() as $errors)
{
foreach($errors as $error)
$content.="
".$footer);
else
return '';
}
/**
* Displays the first validation error for a model attribute.
* @param CModel the data model
* @param string the attribute name
* @return string the error display. Empty if no errors are found.
* @see CModel::getErrors
* @see errorMessageCss
*/
public static function error($model,$attribute)
{
$errors=$model->getErrors($attribute);
if(!empty($errors))
return self::tag('div',array('class'=>self::$errorMessageCss),reset($errors));
else
return '';
}
/**
* Generates the data suitable for {@link dropDownList} and {@link listBox}.
* @param array a list of model objects.
* @param string the attribute name for list option values
* @param string the attribute name for list option texts
* @param string the attribute name for list option group names. If empty, no group will be generated.
* @return array the list data that can be used in {@link dropDownList} and {@link listBox}
*/
public static function listData($models,$valueField,$textField,$groupField='')
{
$listData=array();
if($groupField==='')
{
foreach($models as $model)
$listData[$model->$valueField]=$model->$textField;
}
else
{
foreach($models as $model)
$listData[$model->$groupField][$model->$valueField]=$model->$textField;
}
return $listData;
}
/**
* Generates a valid HTML ID based the name.
* @return string the ID generated based on name.
*/
public static function getIdByName($name)
{
return str_replace(array('[]', '][', '[', ']'), array('', '_', '_', ''), $name);
}
/**
* Generates input field ID for a model attribute.
* @param CModel the data model
* @param string the attribute
* @return string the generated input field ID
* @since 1.0.1
*/
public static function activeId($model,$attribute)
{
return self::getIdByName(self::activeName($model,$attribute));
}
/**
* Generates input field name for a model attribute.
* @param CModel the data model
* @param string the attribute
* @return string the generated input field name
* @since 1.0.1
*/
public static function activeName($model,$attribute)
{
if(($pos=strpos($attribute,'['))!==false)
return get_class($model).substr($attribute,$pos).'['.substr($attribute,0,$pos).']';
else
return get_class($model).'['.$attribute.']';
}
/**
* 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 {@link errorCss}.
* This enables highlighting the incorrect input.
* @param string the input type (e.g. 'text', 'radio')
* @param CModel the data model
* @param string the attribute
* @param array additional HTML attributes for the HTML tag
* @return string the generated input tag
*/
protected static function activeInputField($type,$model,$attribute,$htmlOptions)
{
$htmlOptions['type']=$type;
if(!isset($htmlOptions['value']))
$htmlOptions['value']=$model->$attribute;
if($model->hasErrors($attribute))
self::addErrorCss($htmlOptions);
return self::tag('input',$htmlOptions);
}
/**
* Generates the list options.
* @param mixed the selected value(s). This can be either a string for single selection or an array for multiple selections.
* @param array the option data (see {@link listData})
* @param array additional HTML attributes. The following two special attributes are recognized:
*
*
prompt: string, specifies the prompt text shown as the first list option. Its value is empty.
*
empty: string, specifies the text corresponding to empty selection. Its value is empty.
*
* @return string the generated list options
*/
protected static function listOptions($selection,$listData,&$htmlOptions)
{
$content='';
if(isset($htmlOptions['prompt']))
{
$content.='\n";
unset($htmlOptions['prompt']);
}
if(isset($htmlOptions['empty']))
{
$content.='\n";
unset($htmlOptions['empty']);
}
foreach($listData as $key=>$value)
{
if(is_array($value))
{
$content.=''."\n";
}
else if(!is_array($selection) && !strcmp($key,$selection) || is_array($selection) && in_array($key,$selection))
$content.='\n";
else
$content.='\n";
}
return $content;
}
/**
* Generates the JavaScript with the specified client changes.
* @param string event name (without 'on')
* @param array HTML attributes which may contain the following special attributes
* specifying the client change behaviors:
*
*
submit: string, specifies the URL that the button should submit to. If empty, the current requested URL will be used.
*
params: array, name-value pairs that should be submitted together with the form. This is only used when 'submit' option is specified.
*
confirm: string, specifies the message that should show in a pop-up confirmation dialog.
*
ajax: array, specifies the AJAX options (see {@link ajax}).
*
*/
protected static function clientChange($event,&$htmlOptions)
{
if(isset($htmlOptions['submit']) || isset($htmlOptions['confirm']) || isset($htmlOptions['ajax']))
{
if(isset($htmlOptions['on'.$event]))
{
$handler=trim($htmlOptions['on'.$event],';').';';
unset($htmlOptions['on'.$event]);
}
else
$handler='';
if(isset($htmlOptions['id']))
$id=$htmlOptions['id'];
else
$id=$htmlOptions['id']=isset($htmlOptions['name'])?$htmlOptions['name']:self::ID_PREFIX.self::$_count++;
$cs=Yii::app()->getClientScript();
$cs->registerCoreScript('jquery');
if(isset($htmlOptions['params']))
$params=CJavaScript::encode($htmlOptions['params']);
else
$params='{}';
if(isset($htmlOptions['submit']))
{
$cs->registerCoreScript('yii');
if($htmlOptions['submit']!=='')
$url=CJavaScript::quote(self::normalizeUrl($htmlOptions['submit']));
else
$url='';
$handler.="jQuery.yii.submitForm(this,'$url',$params);return false;";
}
if(isset($htmlOptions['ajax']))
$handler.=self::ajax($htmlOptions['ajax']).'return false;';
if(isset($htmlOptions['confirm']))
{
$confirm='confirm(\''.CJavaScript::quote($htmlOptions['confirm']).'\')';
if($handler!=='')
$handler="if($confirm) {".$handler."} else return false;";
else
$handler="return $confirm;";
}
$cs->registerScript('Yii.CHtml.#'.$id,"jQuery('#$id').$event(function(){{$handler}});");
}
unset($htmlOptions['params'],$htmlOptions['submit'],$htmlOptions['ajax'],$htmlOptions['confirm']);
}
/**
* Generates input name and ID for a model attribute.
* This method will update the HTML options by setting appropriate 'name' and 'id' attributes.
* @param CModel the data model
* @param string the attribute
* @param array the HTML options
*/
protected static function resolveNameID($model,&$attribute,&$htmlOptions)
{
if(!isset($htmlOptions['name']))
{
if(($pos=strpos($attribute,'['))!==false)
$htmlOptions['name']=get_class($model).substr($attribute,$pos).'['.($attribute=substr($attribute,0,$pos)).']';
else
$htmlOptions['name']=get_class($model).'['.$attribute.']';
}
if(!isset($htmlOptions['id']))
$htmlOptions['id']=self::getIdByName($htmlOptions['name']);
}
/**
* Appends {@link errorCss} to the 'class' attribute.
* @param array HTML options to be modified
*/
protected static function addErrorCss(&$htmlOptions)
{
if(isset($htmlOptions['class']))
$htmlOptions['class'].=' '.self::$errorCss;
else
$htmlOptions['class']=self::$errorCss;
}
}