CollectionType提交所有嵌入的表单,只想提交一个

时间:2019-03-08 21:28:58

标签: php symfony symfony-forms

我有一个ColletionType的{​​{1}}表格,每个表格都用于编辑Alert实体的文本内容。我快要解决了,但是提交一个警报的EditType会提交其余的,而EditType会作为内容传递。

collectiontype表单类型

null

嵌入式表单类型

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('alerts', CollectionType::class,
        [
            'entry_type' => EditAlertType::class,
            'entry_options' => ['label' => false],
        ]);
}

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults([
        'data_class' => AlertManager::class
    ]);
}

控制器代码

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('content', TextType::class, ['required' => true]);
    $builder
        ->add('edit', SubmitType::class,
            array
            (
                'label' => 'Save changes',
                'attr' => ['class' => 'btn btn-primary']

            ))
        ;
}

public function configureOptions (OptionsResolver $resolver)
{
    $resolver->setDefaults([
        'data_class' => Alert::class
    ]);
}

0 个答案:

没有答案