简体   繁体   English

如何在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. 顺便说一句,我想创建一个自定义mergeForm,它将包含一个选择字段服务以及一个选择字段Groupe ,以便合并其中一些实体。 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) Symfony 2官方手册正在维护中,所以我想知道如何创建自定义表单,我可以在其中选择服务(来自所有现有服务)并选择一个组(来自所有现有组)

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 (eg 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有一个拉取请求 ,应该可以更轻松地处理这种类型的表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM