F
F
FreeAero2014-04-21 16:28:22
symfony
FreeAero, 2014-04-21 16:28:22

How to fix error when generating CRUD in Symfony2?

Hello, there is a problem when changing an entity via CRUD in symfony2, I generated a crud, I didn’t touch anything, I go to /admin/post/1/edit and I get an error:

The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class SomeHelp\UserBundle\Entity\UserEntity. You can avoid this error by setting the "data_class" option to "SomeHelp\UserBundle\Entity\UserEntity" or by adding a view transformer that transforms an instance of class SomeHelp\UserBundle\Entity\UserEntity to scalar, array or an instance of \ArrayAccess.

I'm assuming it's because of the connected field
/**
 * @ORM\ManyToOne(targetEntity="SomeHelp\UserBundle\Entity\UserEntity",inversedBy="user",cascade={"persist", "remove"})
 */

protected $user;

What to do with it? Please describe in detail.
So the correction, everything works, but the error pops up if the field has a NULL value in the line - can this be avoided?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Slinko, 2014-04-21
@FreeAero

You need to create a form class for UserEntity or remove this field from the main form.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question