本文实例讲述了yii去掉必填项中星号的方法。分享给大家供大家参考,具体如下:
如何去掉必填项里的星号呢?
先分析下代码实现:
html' target='_blank'>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 ?
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP !
相关推荐:
YII如何使用url组件美化管理
关于YII关联查询的解析
以上就是如何用yii去掉必填项中的星号的详细内容,PHP教程
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。
新闻热点
疑难解答