How to pass options to CustomType in `collection` field Symfony 2.1?

前端 未结 2 1920
说谎
说谎 2021-02-05 05:03

I have SuperType Form for Entity Super.

In this form I have a collection field of ChildType Form types for Entity

相关标签:
2条回答
  • 2021-02-05 05:40

    You can pass an array of options to your childType as follows:

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('childrens', 'collection', array(
                'entry_type' => new ChildType(),  
                'entry_options'  => array(
                    'my_custom_option' => true,
                ),
        // ...
    
    }
    
    0 讨论(0)
  • 2021-02-05 05:53

    In Symfony 3, this is called entry_options.

    $builder->add('childrens', CollectionType::class, array(
        'entry_type'   => ChildType::class,
        'entry_options'  => array(
            'my_custom_option'  => true
        ),
    ));
    
    0 讨论(0)
提交回复
热议问题