Php 表单视图中的多对多关系symfony 2
我在两个实体之间有一个多对多的关系 然后显示一个表单,将entityA添加到entityB。 难道不能添加一个定制表单(我的意思是在twig视图中)以允许用户有时选择一个值,有时选择多个值吗 当我希望用户选择多个值时,我使用Php 表单视图中的多对多关系symfony 2,php,symfony,Php,Symfony,我在两个实体之间有一个多对多的关系 然后显示一个表单,将entityA添加到entityB。 难道不能添加一个定制表单(我的意思是在twig视图中)以允许用户有时选择一个值,有时选择多个值吗 当我希望用户选择多个值时,我使用 <select multiple> {% for entity in entitys %} <option> {{entity.id}} </option> {%endfor%} </select> {entitys
<select multiple>
{% for entity in entitys %}
<option>
{{entity.id}}
</option>
{%endfor%}
</select>
{entitys%中实体的%s}
{{entity.id}
{%endfor%}
否则这个
<select >
{% for entity in entitys %}
<option>
{{entity.id}}
</option>
{%endfor%}
</select>
{entitys%中实体的%s}
{{entity.id}
{%endfor%}
但现在的问题是如何提交表格。
<button type="submit" class="btn btn-info" value="NEXT STEP " />
这是整个表格
<form method="post">
<select >
{% for entity in entitys %}
<option>
{{entity.id}}
</option>
{%endfor%}
</select>
<input type="submit" />
</form>
{entitys%中实体的%s}
{{entity.id}
{%endfor%}
不再提交表格。有什么想法吗
这是我的整个树枝视图
<h2> STEP {{step}} </h2>
<form method="post">
<select >
{% for entity in entitys %}
<option value="{{entity.id}}">
{{entity.id}}
</option>
{%endfor%}
</select>
<input type="submit" class="btn btn-info" />
</form>
<br>
<br>
步骤{{STEP}
{entitys%中实体的%s}
{{entity.id}
{%endfor%}
在formbuilder中,您可以添加一些选项,如我的示例:
目的是将字段映射到实体(以设置列表)。别忘了在映射实体中添加一个方法_tostring,使symfony能够将实体表示为select中的文本
在你的表格里
在你的窗体控件中
在你看来
您可以在以下表单中找到有关实体类型的更多信息:
编辑:
从细枝视图中,表单的操作丢失
尝试添加
<form method="post" action="{{ path("theRouteOfYourControllerWitchRecordTheData")}}">
我已经试过了,但是没有结果。你能给我们看一下
表单
标签吗?另外,您如何知道是否需要多重选择?您的问题是表单的渲染效果不好还是/提交时什么都不做?@0x1gene我通过控制器中的一个值知道它。这并不困难。我的问题是它在提交时什么都不做。我将加入我的表单表单表单的操作属性在您的视图中设置得好吗?是的,它显示得很好,当我单击按钮时,它似乎正在提交,但当我检查数据库时,我找不到任何@0x1gene
$editForm = $this->createForm(new FormType(), $entity);
return array(
'form' => $editForm->createView()
);
<form action="{{ path('theControllerActionWitchIsResponsibeOfRecordingIntoDatabase' }}" method="post" {{ form_enctype(edit_form) }}>
{{ form_widget(edit_form) }}
<p>
<button type="submit">Next step</button>
</p>
</form>
select tag expanded=false multiple=false
select tag (with multiple attribute) expanded=false multiple=true
radio buttons expanded=true multiple=false
checkboxes expanded=true multiple=true
<form method="post" action="{{ path("theRouteOfYourControllerWitchRecordTheData")}}">
<select multiple>
{% for entity in entitys %}
<option value="{{entity.id}}">{{entity.name}}</option>
{%endfor%}
</select>