CHtml::activeLabelEx() 會檢查模型屬性是否為必填(CRequiredValidator),若是則在標籤後追加 CHtml::afterRequiredLabel(默認 *)並加上 required CSS 類。
<?php CHtml::$afterRequiredLabel = ''; ?>
<?= $form->labelEx($model, 'email') ?>
亦可自定義為其他提示:CHtml::$afterRequiredLabel = ' (必填)';
// protected/config/main.php 引入一個初始化腳本
'onBeginRequest'=>function() { CHtml::$afterRequiredLabel = ''; }
或在 Controller::init() 中設置,影響全站。
.required::after { content: none; } /* 或 display:none */
配合 CHtml::$requiredCss = 'required'; 生成的類名隱藏星號。