如何在Symfony 2中创建自定义表单

[英]How to create a custom form in Symfony 2


I have three entities : Service, Group, Agent.

我有三个实体:服务,组,代理。

Service => oneToMany => Group => oneToMany => Agent

Service => oneToMany => Group => oneToMany => Agent

Each of these entities already have a form. By the way, I would like to create a custom mergeForm which will contains a select field Service to choose and a select field Groupe in order to merge some of these entities. The Symfony 2 official cookbook is under maintenance, so I would like to know the way to create the custom Form in which I will be able to choose a Service (from all existing services) and to choose a Group (from all existing groups)

这些实体中的每一个都已有表格。顺便说一句,我想创建一个自定义mergeForm,它将包含一个选择字段服务以及一个选择字段Groupe以合并其中一些实体。 Symfony 2官方手册正在维护中,所以我想知道创建自定义表单的方法,在该表单中我将能够选择服务(来自所有现有服务)并选择一个组(来自所有现有组)

1 个解决方案

#1


0  

What you're looking for is probably entity field type. This will allow you to embed within the form a select field that points to the foreign entity. This is primarily useful for small collections.

您正在寻找的可能是实体字段类型。这将允许您在表单中嵌入指向外部实体的选择字段。这主要适用于小型集合。

When you start dealing with large collections, and find the need/desire to load entities with Javascript (e.g. The collection is to large to justify loading all on page-load), you'll have to look at Symfony2 Documentation: How to Embed a Collection of Forms.

当您开始处理大型集合时,发现需要/希望使用Javascript加载实体(例如,集合很大以证明在页面加载时加载所有内容),您将不得不查看Symfony2文档:如何嵌入表格集。

It's also worth noting that there is a pull request slated for Symfony 2.2 that is supposed to make dealing with this type of form easier.

同样值得注意的是,Symfony 2.2有一个拉动请求,应该可以更容易地处理这种类型的形式。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2012/06/20/70011258026cccadf9fe15480e08c5eb.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告