• 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'); ?>

  • 相关阅读:
    SpringBoot进阶教程(六十七)RateLimiter限流
    Nginx限流配置
    ab test压力测试
    Nginx负载均衡配置
    arduino串口通信
    flask文件路径设置问题
    WIN10和ubunu共享文件夹相互访问
    树莓派录音和播放声音
    深度学习论文翻译解析(十六):Squeeze-and-Excitation Networks
    人工智能必备数学基础:高等数学基础(2)
  • 原文地址:https://www.cnblogs.com/xiongsd/p/3054821.html
Copyright © 2020-2023  润新知