search
Homephp教程php手册yii 去掉必填项的星号

yii 去掉必填项的星号

Jun 13, 2016 am 10:54 AM
publicyiiDowncodeanalyzeremoveWoolen clothhowaccomplishof

如何去掉必填项里德星号呢?

先分析下代码实现:

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)www.2cto.com

{

foreach($this->getValidators($attribute) as $validator)

{

if($validator instanceof CRequiredValidator) return true;

}

return false;

}

所以要去掉星号 或者换成别的可以再view中直接重新定义CHtml::requiredCss、CHtml::beforeRequiredLabel、CHtml::afterRequiredLabel即可

不显示星号就可这样

labelEx($model,'email'); ?>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment