我有以下实体关系:
- 客户有一对多地址
- 一个地址有多对一的县和多对一的市
- 一个县有一对多的城市。
所以,在我的 CustomerType 中,我有
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
...
->add('addresss', 'collection', array(
'label' => 'customer.address',
'type' => new AddressType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
))
;
}
在我的 AddressType 中,我有
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
...
->add('city', 'entity', array(
'class' => 'MyCustomerBundle:City',
'query_builder' => function(CityRepository $cr) use ($options) {
return $cr->getCityQB($options['county']);
},
'property' => 'city',
'empty_value' => '',
))
;
}
我的目标是只显示相应县的城市集。我可以从 $options 中获取 CustomerType 中的值,但是如何将这些值传递给 AddressType?以便每个地址都得到其对应的县来查找城市?
如有任何帮助,我们将不胜感激。谢谢!
最佳答案
在 symfony3 中:
$builder->add('example', CollectionType::class, array(
'entry_type' => ExampleType::class,
'entry_options' => array(
'my_custom_option' => true),
));
关于php - Symfony2 将值传递给集合表单类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15199784/