简体   繁体   中英

How to create a custom form in Symfony 2

I have three entities : Service, Group, 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)

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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