I wish to generate the following markup:
<label>some label here <span>(optional)</span></label>
Is there a way to do this, by using Yii labelEx or just label?
Thanks
I wish to generate the following markup:
<label>some label here <span>(optional)</span></label>
Is there a way to do this, by using Yii labelEx or just label?
Thanks
It's simple, make use of the Decorator pattern:
use case:
Here is a little hack to make it possible.
You could use
CHtml::$afterRequiredLabel
and/orCHtml::$beforeRequiredLabel
This way the label will be applied only on the specified form field. You actually set the initial value of
CHtml::$afterRequiredLabel
and/orCHtml::$beforeRequiredLabel
on a temp variable, you overwrite the value that you need, and then reset it to original value.If the attribute is required
You can set the CHtml static properties like this
Yii will generate a tag
but the static properties will effect all labels generated by $form->labelEx() (@see CHtml::activeLabelEx())
if you don't need, you must set the static properties to default
If the attribute is not required
you can set the htmlOptions