如果我在窗体中显示“实体”类型的字段,并且我想根据从控制器传递的参数过滤此实体类型,那么我该怎么做?将数据从控制器传递到类型symfony2
//PlumeOptionsType.php
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('framePlume', 'entity', array(
'class' => 'DessinPlumeBundle:PhysicalPlume',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('pp')
->where("pp.profile = :profile")
->orderBy('pp.index', 'ASC')
->setParameter('profile', ????)
;
},
));
}
public function getName()
{
return 'plumeOptions';
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Dessin\PlumeBundle\Entity\PlumeOptions',
'csrf_protection' => true,
'csrf_field_name' => '_token',
// a unique key to help generate the secret token
'intention' => 'plumeOptions_item',
);
}
}
,并在控制器内,我创建表单:
i have that argument that i need to pass in my action code:
$profile_id = $this->getRequest()->getSession()->get('profile_id');
...
and then i create my form like this
$form = $this->createForm(new PlumeOptionsType(), $plumeOptions);
的$ plumeOptions只是坚持一个类。但它与另一个称为PhysicalPlume的类有一对一的关系。现在,当我想在我的代码中显示'framePlume'时,我想显示一个过滤的PhysicalPlume实体。
已回答... 检查http://stackoverflow.com/questions/6716776/symfony-2-how-to-pass-data-to-for mbuilder – xeon