What should I do when a form choice field depends on property of domain object. I have insurance field that should contain insurances of specific user.
http://pastie.org/2132730
Thanks in advan开发者_Python百科ce
If the insurance choices are a known value of the user, then you can pass them in as options when you create your form:
$form = $this->createForm(new AgentContractFormType(), $agentContract, array(
'insurances' => array(/* insurance choices here */),
));
then in your form class:
public function getDefaultOptions(array $options)
{
return array(
'insurances' => $options['insurances'],
'data_class' => 'NTO\DocumentBundle\Entity\Document\AgentContract',
);
}
You can then use them in buildForm()
as you please. Hope that helps.
精彩评论