获取未在 FormType 中声明的字段的值 [英] Get value of a field not declared in FormType
本文介绍了获取未在 FormType 中声明的字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 nameType.php
中声明了一个表单,视图呈现所有字段,但我想手动添加另一个字段.
I have a form declared in nameType.php
and the view render all field but I want add another field manually.
表格:
<form action="{{ path('create') }}" method="post" {{ form_enctype(form) }}>
{{ form_widget(form) }}
<input type="text" value="2">
</form>
并获取控制器中的值:
$form->bindRequest($request);
如何收集控制器中输入的值?
How can I collect the value of the input in the controller?
推荐答案
如果您尝试这样做是因为表单链接到您的实体字段,您可以将一个字段添加到 FormType 中作为未映射.那么您的实体就不需要 getter 和 setter.
If you are trying this because the form is linked to your entity field you can add a field to FormType as not mapped. Then you do not need getters and setters on your entity.
->add("inputName", "text", array("mapped"=>false, "data"=>2, "label"=>false))
获取控制器中的数据:
$form->get("inputName")->getData();
这篇关于获取未在 FormType 中声明的字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文