Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Ttwig中为表单自动重新编写输入标签?_Php_Symfony_Twig - Fatal编程技术网

Php 如何在Ttwig中为表单自动重新编写输入标签?

Php 如何在Ttwig中为表单自动重新编写输入标签?,php,symfony,twig,Php,Symfony,Twig,我在Twig中使用了几乎标准的CRUD表单渲染: {{ form_start(form, {'attr' : {'class' : 'new_edit_form'}}) }} {{ form_widget(form) }} <input type="submit" value="{{ 'default.new.create'|trans }}"/> {{ form_end(form) }} 我在项目中启用了翻译,Twig尝试翻译这些单词,但在我的字典中,所有属性都有ID,如fiel

我在Twig中使用了几乎标准的CRUD表单渲染:

{{ form_start(form, {'attr' : {'class' : 'new_edit_form'}}) }}
{{ form_widget(form) }}
<input type="submit" value="{{ 'default.new.create'|trans }}"/>
{{ form_end(form) }}
我在项目中启用了翻译,Twig尝试翻译这些单词,但在我的字典中,所有属性都有ID,如field.property\u name。 所以我想检查所有表单输入,重写所有标签,使其小写,并添加“字段”。前缀。如何在循环中完成此操作


Symfony 3.4

要覆盖翻译,您需要将
messages.en.yml
添加到
应用程序/YourBundle/Resources/translations
中,并覆盖您想要的信息,如:
field.property\u名称:此处的标签


这可能会有帮助:

为了覆盖翻译,您需要将
messages.en.yml
添加到
应用程序/YourBundle/Resources/translations
中,并覆盖您想要的消息,如:
field.property\u名称:此处的标签


这会有所帮助:

您可以为每个字段定义特定的标签:

$builder->add('save', TextType::class, array(
    'label' => 'field.sth'
))

可以为每个字段定义特定标签:

$builder->add('save', TextType::class, array(
    'label' => 'field.sth'
))

不确定您使用的是什么框架,但通常情况下,我们有此函数:uu($field.property\u name),如果有翻译文本,它将返回给您,否则使用默认语言可能与您使用的框架重复,但通常我们有此函数:uu($field.property\u name),它将返回一个翻译文本(如果有),否则使用默认语言可能重复