0

我将 EasyAmdin 3 与 Symfony 5 一起使用,并且在 Challenge 和 Encadrement 之间存在 OneToMany 关系。在 Challenge.php 中定义:

/**
 * @ORM\OneToMany(targetEntity=Encadrement::class, mappedBy="challengePartner")
 */
private $bornes;

我为 Challenge 制作了一个 CRUDController,我希望能够在创建/编辑 Challenge 时直接添加 Encadrement。我这样做了:

        AssociationField::new('bornes'),

我可以在所有已创建的 Encadrement 之间进行选择。但我想要的是能够多次添加 Encadrement,但我找不到如何做到这一点。我尝试制作自己的 EncadrementType :

class EncadrementType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name', TextType::class, array(
                "label" => "Nom"
            ))
            ->add('low', IntegerType::class, array(
                "label" => "Borne basse"
            ))
            ->add('high', IntegerType::class, array(
                "label" => "Borne haute"
            ))
        ;
    }

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

在 ChallengeCRUD 中是这样的:

        AssociationField::new('bornes')->setFormType(EncadrementType::class),

但是当我什至不使用这些选项时,我会收到此错误:

An error has occurred resolving the options of the form "App\Form\EncadrementType": The options "class", "multiple", "query_builder" do not exist. Defined options are: "action", "allow_extra_fields", "allow_file_upload", "attr", "attr_translation_parameters", "auto_initialize", "block_name", "block_prefix", "by_reference", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "ea_crud_form", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "getter", "help", "help_attr", "help_html", "help_translation_parameters", "inherit_data", "invalid_message", "invalid_message_parameters", "is_empty_callback", "label", "label_attr", "label_format", "label_html", "label_translation_parameters", "legacy_error_messages", "mapped", "method", "post_max_size_message", "property_path", "required", "row_attr", "setter", "translation_domain", "trim", "upload_max_size_message", "validation_groups".

我尝试将多个选项添加到 AssociationField 但它什么也没做:

        AssociationField::new('bornes')->setFormTypeOption("multiple","true"),

我被困在那里,感谢您的帮助!

4

1 回答 1

0

像这样尝试 CollectionField:

<?php
yield CollectionField::new('bornes')
    ->setFormTypeOptions([
        'delete_empty' => true,
        'by_reference' => false,
    ])
    ->setEntryIsComplex(false)
    ->setCustomOptions([
        'allowAdd' => true,
        'allowDelete' => true,
        'entryType' => EncadrementType::class,
        'showEntryLabel' => false,
    ])
    ;
于 2021-06-03T11:07:56.940 回答