I am developing a web system to manage soccer academies, for this I must register a player and assign preferred playing positions, one or more can be selected through checkboxes.
My case is the following:
In the Player entity I have created a field principal_positions
#[ORM\Column(length: 255, nullable: true)]
private ?string $principal_positions = null;
Which will receive the positions of the player_position entity
I have created an EntityType field to display the checkboxes as follows
->add('principal_positions', EntityType::class, [
'class' => PlayerPosition::class,
'choice_value' => 'label',
'choice_label' => 'label',
'expanded' => true,
'multiple' => true,
'required' => true,
'label_attr' => [
'class' => 'form-check-label'
]
])
When entering the form everything is displayed perfectly, but when the form is submitted, garbage is saved
Doctrine\Common\Collections\ArrayCollection@000000000000087f0000000000000000
So the questions I ask are:
- What is the best strategy to implement multiple option selection using ChoiceType or EntityType checkboxes?
- What is the correct way to display and store in the player entity the list of positions using ChoiceType?
- What is the correct way to display and store in the player entity the position list using EntityType?
Thanks