V
V
vladislav9972021-06-01 12:10:31
symfony
vladislav997, 2021-06-01 12:10:31

How to convert the array correctly when submitting the form to the view?

Tell me how to convert the array correctly when submitting the form to the Symfony view?

There are 2 entities: Chat and Group, they have a ManyToOne relationship. You need to make a view with the ability to edit the chat, and in it edit the group with which the chat has a connection. I made a form, cut it in the controller and passed it to the view, but the following error pops up:

Object of class Proxies\__CG__\App\Entity\Group could not be converted to string


In the form itself, if I comment on the line with group, then it's OK, but there is no way to edit the connecting group in this chat:
$builder
            ...
            ->add('group')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2021-06-01
@vladislav997

Either add a method \App\Entity\Group::__toStringor add a choice_label option

->add('group', null, [
    'choice_label' => 'getName', // Метод, который вернет название группы
])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question