开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜