开发者

What to do when form choice field depends on value of domain object property

开发者 https://www.devze.com 2023-03-15 18:30 出处:网络
What should I do when a form choice field depends on property of domain object. I have insurance field that should contain insurances

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号