我有以下实体关系:
>客户具有一对多地址
>地址有多对一的县和多对一的城市
>一个县有一对多的城市.
所以,在我的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中,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?那么每个地址都有相应的县来查找城市?
任何帮助,将不胜感激.谢谢!
使用AddressType中的构造函数,它适用于我..
原文链接:https://www.f2er.com/php/132379.html客户类型:
public function buildForm(FormBuilderInterface $builder,'type' => new AddressType($your_variable),)) ; }
地址类型:
private $your_variable; public function __construct($variable) { $this->your_variable= $variable; } ... public function buildForm(FormBuilderInterface $builder,array $options){ $your_variable = $this->your_variable; 'query_builder' => function(CityRepository $cr) use ($your_variable) { return $cr->getCityQB($your_variable); },}