最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

相關(guān)文章

最新評(píng)論

宁武县| 子洲县| 新和县| 水富县| 竹山县| 郓城县| 天水市| 双鸭山市| 海原县| 平顶山市| 宁安市| 阜南县| 西昌市| 华蓥市| 沙河市| 右玉县| 教育| 普兰店市| 定襄县| 商洛市| 祥云县| 桑植县| 清流县| 涞源县| 定日县| 邻水| 涞水县| 石狮市| 晋宁县| 邵阳县| 张家港市| 台安县| 株洲市| 手机| 南宁市| 苍南县| 平顶山市| 岳池县| 蓬溪县| 广东省| 平远县|