Yii2 attributeLabels - 在标记中包装标签的一部分

时间:2015-06-25 15:23:31

标签: yii yii2

Inside User模型,我使用attributeLabels方法为字段创建文本:

public function attributeLabels()
    {
        return [
            'terms'            => 'I accept the Terms and Coditions'
        ];
    }

在视图中我使用标准 $ form->字段方法来显示输入字段:

<?php $form->field($model, 'terms')->checkbox() ?>

我需要在带有链接的标记中包含条款和Coditions 。我怎么能这样做?

1 个答案:

答案 0 :(得分:4)

checkbox()方法采用一个options数组,您可以在其中覆盖默认标签:

$form->field($model, 'terms')->checkbox([
    'label' => 'I accept the <a href="/tos.html" target="_blank">Terms and Conditions</a>'
]);

详细的复选框选项位于http://www.yiiframework.com/doc-2.0/yii-widgets-activefield.html#checkbox()-detail

的API文档中