yii去掉必填项中星号的方法
网络编程 2021-07-05 09:09www.168986.cn编程入门
这篇文章主要介绍了yii去掉必填项中星号的方法,实例分析了Yii中去除必填项中星号的原理与具体实现技巧,需要的朋友可以参考下
本文实例讲述了yii去掉必填项中星号的方法。分享给大家供大家参考,具体如下:
如何去掉必填项里的星号呢?
先分析下代码实现:
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); }
当属性是必填的时候,它将渲染额外的CSS类个标记。特别的,它调用CModel::isAttributeRequired来决定属性是否为必填的。如果是,它将添加一个CSS类CHtml::requiredCss (public static $requiredCss='required';)到标签上,用CHtml::beforeRequiredLabel(public static $beforeRequiredLabel='';)和CHtml::afterRequiredLabel (public static $afterRequiredLabel='*';)来装饰标签。
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 CHtml::$afterRequiredLabel = '';?> <?php echo $form->labelEx($model,'email'); ?>
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。
上一篇:YII使用url组件美化管理的方法
下一篇:Yii中实现处理前后台登录的新方法
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程