>  기사  >  백엔드 개발  >  yii 去掉必填项的星号_PHP教程

yii 去掉必填项的星号_PHP教程

WBOY
WBOY원래의
2016-07-14 10:08:141001검색

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

先分析下代码实现:
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'); ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477799.htmlTechArticle如何去掉必填项里德星号呢? 先分析下代码实现: public function labelEx($model,$attribute,$htmlOptions=array()) { return CHtml::activeLabelEx($model,$attribute,$...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.