欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

yii去掉必填項(xiàng)中星號(hào)的方法

 更新時(shí)間:2015年12月28日 12:07:49   作者:zm2714  
這篇文章主要介紹了yii去掉必填項(xiàng)中星號(hào)的方法,實(shí)例分析了Yii中去除必填項(xiàng)中星號(hào)的原理與具體實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了yii去掉必填項(xiàng)中星號(hào)的方法。分享給大家供大家參考,具體如下:

如何去掉必填項(xiàng)里的星號(hào)呢?

先分析下代碼實(shí)現(xiàn):

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);
}

當(dāng)屬性是必填的時(shí)候,它將渲染額外的CSS類個(gè)標(biāo)記。特別的,它調(diào)用CModel::isAttributeRequired來決定屬性是否為必填的。如果是,它將添加一個(gè)CSS類CHtml::requiredCss (public static $requiredCss='required';)到標(biāo)簽上,用CHtml::beforeRequiredLabel(public static $beforeRequiredLabel='';)和CHtml::afterRequiredLabel (public static $afterRequiredLabel='*';)來裝飾標(biāo)簽。

public function isAttributeRequired($attribute)
{
  foreach($this->getValidators($attribute) as $validator)
  {
    if($validator instanceof CRequiredValidator) return true;
  }
  return false;
}

所以要去掉星號(hào) 或者換成別的可以再view中直接重新定義CHtml::requiredCss、CHtml::beforeRequiredLabel、CHtml::afterRequiredLabel即可

不顯示星號(hào)就可這樣

<?php CHtml::$afterRequiredLabel = '';?>
<?php echo $form->labelEx($model,'email'); ?>

希望本文所述對大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論