Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: How to pass parameters to form collections

Tags:

forms

symfony

I'm using a form(parent form) with a collection field type(child forms). Each type in the collection is a form that contains some choice fields, I want to filter this field choices using query_builder parameter for join with other entities ect. I know how to pass parameters to parent form from controller, but how to pass parameters to each item in the collection (child forms)?

like image 498
smoreno Avatar asked Mar 01 '12 17:03

smoreno


1 Answers

What you want is a data transformer. The data transformer takes data from your sub forms allows you to do queries to the database from inside it and pass 1 final result out the end. I had to do this the other day with country and postal code to find a valid postal code in a country.

Here's the link to the cookbook info that will show you how to use it.

http://symfony.com/doc/current/cookbook/form/data_transformers.html

like image 152
thenetimp Avatar answered Nov 15 '22 09:11

thenetimp