Yii removes the asterisk from the required fields, and the asterisk in the Yii mandatory fields
This example describes how Yii removes asterisks from required fields. Share to everyone for your reference, as follows:
How do I get rid of the asterisk in the required fields?
First analyze the following 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 a property is required, it renders additional CSS class tags. In particular, it calls cmodel::isattributerequired to determine if a property is required. If it is, it adds a CSS class chtml::requiredcss (public static $REQUIREDCSS = ' required ';) to the label, with Chtml::beforerequiredlabel (public static $beforeRequiredLabel = ";) and Chtml::afterrequiredlabel (public static $afterRequiredLabel = ' * ';) to decorate the label.
Public Function isattributerequired ($attribute) { foreach ($this->getvalidators ($attribute) as $validator) { if ($validator instanceof Crequiredvalidator) return true; } return false;}
So you have to remove the asterisk or replace it with another view directly redefine Chtml::requiredcss, Chtml::beforerequiredlabel, Chtml::afterrequiredlabel can
Do not display an asterisk
<?php CHtml:: $afterRequiredLabel = ";? ><?php echo $form->labelex ($model, ' email ');?>
It is hoped that this article is helpful to the PHP program design based on YII framework.
Articles you may be interested in:
- The directory structure, portal files, and routing settings for the Yii introductory tutorial
- Yii Installation and Hello World
- YII PHP Framework Practical Introductory Tutorial (detailed)
- Yii Query Builder Usage Example tutorial
- Yii uses URL components to beautify the management method
- The method of Cgridview implementation in Yii for batch deletion
- Methods of Yii Authority control (three methods)
- The query method of Yii database
- Yiiframework Introductory Knowledge Point Summary (graphic tutorial)
http://www.bkjia.com/PHPjc/1085881.html www.bkjia.com true http://www.bkjia.com/PHPjc/1085881.html techarticle Yii removes the asterisk in the required fields, and the asterisk in the mandatory fields of Yii This example describes the method by which Yii removes the asterisk from the required fields. Share to everyone for your reference, as follows: How to remove ...