Код: Выделить всё
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('id', HiddenType::class, [])
->add('band', EntityType::class, [
'class' => Band::class,
'choice_label' => 'band',
'choice_value' => 'band',
'attr' => ['class' => 'py-2 px-4 ml-2 mt-1 border border-gray-300']
])
->add('mode', TextType::class, [
'attr' => ['class' => 'w-full py-2 px-4 ml-2 mt-1 border border-gray-300']
])
->add('frequency', NumberType::class, [
'scale' => 4,
'invalid_message' => 'The frequency is invalid.',
'attr' => ['class' => 'w-full py-2 px-4 ml-2 mt-1 border border-gray-300']
])
->add('comments', TextareaType::class, [
'attr' => ['class' => 'w-full py-2 px-4 ml-2 mt-1 border border-gray-300']
])
->add('submit', SubmitType::class, [
'attr' => ['class' => 'rounded-md font-bold border py-2 px-4 mx-auto bg-blue-500',
'onclick' => 'SubmitOpSession'],
])
;
}
< /code>
Некоторые поля опущены ... Форма создается в контроллере: < /p>
$form = $this->createForm(MyFormType::class, $ThisOpSession, [
'attr' => ['class' => 'w-full'],
'action' => $this->generateUrl('myendpoint'),
]);
$form->handleRequest($Request);
Форма отображает штраф на начальной загрузке страницы. При отправке (post) с данными формы я получаю: < /p>
Код: Выделить всё
App\Entity\OpSession::setBand(): Argument #1 ($band) must be of type string, App\Entity\Band given, called in /var/www/rtqm/vendor/symfony/property-access/PropertyAccessor.php on line 532
Что мне не хватает?
Код: Выделить всё
$BandRepo = $entityManager->getRepository(Band::class);
$Bands = $BandRepo->findAll();
$form = $this->createForm(OpSessionFormType::class, $ThisOpSession, [
'attr' => ['class' => 'w-full'],
'action' => $this->generateUrl('osmanager'),
'bands' => $Bands,
]);
Код: Выделить всё
->add('band', ChoiceType::class, [
'choices' => $options['bands'],
'choice_label' => 'band',
'choice_value' => 'band',
])
Подробнее здесь: https://stackoverflow.com/questions/795 ... e-when-usi