EasyAdmin 3 Symfony 5 CrudController 关联字段
EasyAdmin 3 Symfony 5 CrudController AssociationField
我将 EasyAmdin 3 与 Symfony 5 一起使用,并且我在 Challenge 和 Encadrement 之间存在 OneToMany 关系。定义于 Challenge.php:
/**
* @ORM\OneToMany(targetEntity=Encadrement::class, mappedBy="challengePartner")
*/
private $bornes;
我为Challenge做了一个CRUDController,我希望在creating/editing一个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"),
我被困在那里,感谢您的帮助!
像这样尝试 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,
])
;
我将 EasyAmdin 3 与 Symfony 5 一起使用,并且我在 Challenge 和 Encadrement 之间存在 OneToMany 关系。定义于 Challenge.php:
/**
* @ORM\OneToMany(targetEntity=Encadrement::class, mappedBy="challengePartner")
*/
private $bornes;
我为Challenge做了一个CRUDController,我希望在creating/editing一个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"),
我被困在那里,感谢您的帮助!
像这样尝试 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,
])
;