Symfony2自定义表单 [英] Symfony2 custom form

查看:107
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆