Symfony Form with subform

时间:2015-06-26 10:18:48

标签: php symfony symfony-forms symfony-2.6

I have a user form and a contact form in my user form i tried to add my contact form to the user form

When I tried to add

$builder->add(
            'contact',
            new ContactType()
        );

It failed with

You cannot add children to a simple form.
Maybe you should set the option "compound" to true?

tried to set the compound but didnt work

/**
 * {@inheritdoc}
 */
public function configureOptions(OptionsResolver $resolver)
{
    $defaults = array(
        'compound' => true,
        'inherit_data' => true,
    );

    $resolver->setDefaults($defaults);
}

1 个答案:

答案 0 :(得分:7)

compound选项默认设置为true

  1. 您是如何扩展表单类型的? AbstractFormType或其他什么?
  2. 您是否覆盖了getParent()方法?
  3. 这可以解释compound被设置为false