Yii removes the required asterisks. How do I remove the required Reed asterisk? Analyze the code implementation: publicfunctionlabelEx ($ model, $ attribute, $ htmlOptionsarray () {returnCHtml: activeLabelEx ($ model, $ attribute, $ How do I remove the required Reed asterisk?
First, analyze the code implementation:
Public function labelEx ($ model, $ attribute, $ htmlOptions = array ())
{
Return CHtml: activeLabelEx ($ model, $ attribute, $ htmlOptions );
}
Public static function activeLabelEx ($ model, $ attribute, $ htmlOptions = array ())
{
$ RealAttribute = $ attribute;
Self: resolveName ($ model, $ attribute); // strip off square brackets if any
$ HtmlOptions ['required'] = $ model-> isAttributeRequired ($ attribute );
Return self: activeLabel ($ model, $ realAttribute, $ htmlOptions );
}
When the attribute is required, it will render an additional CSS class tag. Specifically, it calls CModel: isAttributeRequired to determine whether the attribute is required. If yes, it adds a CSS class CHtml: requiredCss (public static $ requiredCss = 'required';) to the tag and uses CHtml :: beforeRequiredLabel (public static $ beforeRequiredLabel = '';) and CHtml: afterRequiredLabel (public static $ afterRequiredLabel = '*';) to decorate tags.
Public function isAttributeRequired ($ attribute) www.2cto.com
{
Foreach ($ this-> getValidators ($ attribute) as $ validator)
{
If ($ validator instanceof CRequiredValidator) return true;
}
Return false;
}
Therefore, to remove the asterisk or change it to another option, you can re-define CHtml: requiredCss, CHtml: beforeRequiredLabel, CHtml: afterRequiredLabel in the view.
If the asterisk is not displayed
LabelEx ($ model, 'Email ');?>
Why? First, analyze the code implementation: public function labelEx ($ model, $ attribute, $ htmlOptions = array () {return CHtml: activeLabelEx ($ model, $ attribute, $...