【问题标题】:Split the Form Label code and Form Value code in Symfony view在 Symfony 视图中拆分表单标签代码和表单值代码
【发布时间】:2017-09-14 09:14:56
【问题描述】:

StudentType.php

$builder->add('internalId', null, array(
    'label' => "Student ID",
    'attr' => array('class' => 'studentInternalId', 'size' => 10, 'readonly' => 'readonly', 'placeholder' => 'Auto-generated', 'style' => 'width: 80px;', 'tabindex' => '-1', 'style' => 'pointer-events:none; opacity: 0.8; cursor: not-allowed')
));

index.html.twig

{{ form_row(contractStudent.student.internalId) }}

输出:

Label : InputField

我可以为 Label 编写单独的代码,为在 index.html.twig 文件中显示的值编写单独的代码吗?

我想在用户点击链接时创建一个价值链接,我会将用户带到另一个页面。为此,我需要该字段值。

【问题讨论】:

    标签: php forms symfony


    【解决方案1】:

    只渲染字段:

    {{ form_widget(form.name) }}
    

    对于标签:

    {{ form_label(form.name) }}
    

    【讨论】:

      猜你喜欢
      • 2016-11-27
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      相关资源
      最近更新 更多