PHP编程:yii去掉必填项中星号的方法
《yii去掉必填项中星号的方法》要点: 本篇章节讲解yii去掉必填项中星号的办法.分享给大家供大家参考,具体如下:PHP编程 如何去掉必填项里的星号呢?PHP编程 先分析下代码实现:PHP编程 public function labelEx($model,$attribute,$htmlOptions=array()) { return CHtml::activeLabelEx($model,$htmlOptions); } public static function activeLabelEx($model,$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); } 当属性是必填的时候,它将渲染额外的CSS类个标记.特别的,它调用CModel::isAttributeRequired来决定属性是否为必填的.如果是,它将添加一个CSS类CHtml::requiredCss (public static $requiredCss='required';)到标签上,用CHtml::beforeRequiredLabel(public static $beforeRequiredLabel='';)和CHtml::afterRequiredLabel (public static $afterRequiredLabel='*';)来装饰标签.PHP编程 public function isAttributeRequired($attribute) { foreach($this->getValidators($attribute) as $validator) { if($validator instanceof CRequiredValidator) return true; } return false; } 所以要去掉星号 或者换成别的可以再view中直接重新定义CHtml::requiredCss、CHtml::beforeRequiredLabel、CHtml::afterRequiredLabel即可PHP编程 不显示星号就可这样PHP编程 <?php CHtml::$afterRequiredLabel = '';?> <?php echo $form->labelEx($model,'email'); ?> 希望本文所述对大家基于Yii框架的PHP程序设计有所赞助.PHP编程 《yii去掉必填项中星号的方法》是否对您有启发,欢迎查看更多与《yii去掉必填项中星号的方法》相关教程,学精学透。编程之家 52php.cn为您提供精彩教程。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |