要生成以下标记:
<label class="foo">Bar</label>
PHP 看起来像:
<?php echo $form->label($model,'username'); ?>
似乎它应该是 label() 的 htmlOptions 参数的一部分,但我无法真正弄清楚。
来自 Yii 的文档:
public string label(CModel $model, string $attribute, array $htmlOptions=array ( ))
引用:
http://www.yiiframework.com/doc/api/1.1/CActiveForm#label-detail
最佳答案
正如文档所说,$htmlOptions 是一个附加 HTML 属性的数组。键是属性,值是属性值,所以给标签添加一个类属性:
<?php echo $form->label( $model,'username', array('class'=>'className') ); ?>
关于forms - 如何在 Yii 表单标签中添加一个类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11318339/