Symfony2自定义表单 [英] Symfony2 custom form
本文介绍了Symfony2自定义表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
+ ------------------- ---------------- +
| id | parent_id |名称|
+ ----------------------------------- +
| 1 | NULL |区域|
+ ----------------------------------- +
| 2 | 1 |区|
+ ----------------------------------- +
| 3 | 1 |另一个区|
+ ----------------------------------- +
| 4 | NULL |另一个区域|
+ ----------------------------------- +
| 5 | 4 |下一个区|
+ ----------------------------------- +
问题是我需要以下表单。怎么做?
< b>区域< / b><! - 从数据库加载 - >
<! - 按名称排序的描述 - >
< input type =checkboxid =someIdvalue =3>< label for =someId>另一个区域< / label>
< input type =checkboxid =someIdvalue =2>< label for =someId>区< / label>
< b>另一个区域< / b><! - 从数据库加载 - >
<! - 按名称排序的描述 - >
< input type =checkboxid =someIdvalue =5>< label for =someId>下一个区域< / label>
解决方案
I have form with checkboxes loaded from database (I use entity field type). Checkboxes are regions and districts. I have following database schema:
+-----------------------------------+
| id | parent_id | name |
+-----------------------------------+
| 1 | NULL | Region |
+-----------------------------------+
| 2 | 1 | District |
+-----------------------------------+
| 3 | 1 | Another district |
+-----------------------------------+
| 4 | NULL | Another region |
+-----------------------------------+
| 5 | 4 | Next district |
+-----------------------------------+
Problem is that I need following form. How to do that?
<b>Region</b><!-- Loaded from database -->
<!-- Dictricts ordered by name -->
<input type="checkbox" id="someId" value="3"><label for="someId">Another district</label>
<input type="checkbox" id="someId" value="2"><label for="someId">District</label>
<b>Another region</b><!-- Loaded from database -->
<!-- Dictricts ordered by name -->
<input type="checkbox" id="someId" value="5"><label for="someId">Next district</label>
解决方案
Thanks to this post I've solve this by custom rendering form template.
这篇关于Symfony2自定义表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文