【问题标题】:Html tag is not working inside model attribute label in Yii2html标签在Yii2的模型属性标签内不起作用
【发布时间】:2020-07-05 04:44:53
【问题描述】:

Html 标签在 Yii2 中的模型属性标签内不起作用

  public function attributeLabels() {
            return [
       'name'=>' Name <br> Age',
            ];
        }

Br 标记在那里不起作用,它在 UI 中显示
标记。

public function attributeLabels() {
        $labels = [
            'id' => 'ID',
            'model_id' => 'Form Name',
            'user_id' => 'User Name',
        ];
        $model = $this->getFields(UcFormFields::STATIC_FIELDS);

        foreach ($model as $field)
            $labels[$field->varname] = Yii::t('app', $field->title);

        $model = $this->getFields(UcFormFields::DYNAMIC_FIELDS);

        foreach ($model as $field)
            $labels[$field->varname] = "Question \n Instruction.."; // will be replaced by variable

        $model = $this->getDepFields(UcFormFields::DYNAMIC_FIELDS);
        foreach ($model as $field)
            $labels[$field->varname] = Yii::t('app', $field->title);

        return $labels;
    }

以上是实际代码....

【问题讨论】:

  • 请正确缩进你的代码,很难理解。
  • 好的,我现在已经编辑过了。
  • 尝试使用 \n 代替
    并将您的值封装在双引号而不是单引号中
  • 这是什么原因?为什么你的标签有两个名字,比如NameAge?实体的每个属性都假设有一个标签。而且你不应该在模型中有任何 html 属性。这必须在视图文件中处理。
  • 试过了,UI中没有出现\n标签,但是没有断线

标签: php forms activerecord yii2


【解决方案1】:
$form->field($model, 'termsofuse')
->checkbox(['label' => Yii::t('app', 'I understand and agree to the <a href="#termsofuse">Terms of Use</a>.')])
->label(false);

更多信息请访问Add encodeLabel in activeLabel #4039

【讨论】:

  • 但它没有出现在下面的验证消息中,“我理解并同意 使用条款 不能为空白”.. 它带有 HTML 标签
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-13
  • 2017-08-25
  • 1970-01-01
  • 1970-01-01
  • 2021-11-17
  • 2015-12-15
  • 1970-01-01
相关资源
最近更新 更多