This is my error:
The form's view data is expected to be an instance of class My\Bundle\Entity\Tags, but is an instance of class Doctrine\Common\Collections\ArrayCollection. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms an instance of class Doctrine\Common\Collections\ArrayCollection to an instance of My\Bundle\Entity\Tags
and this is my form builder
$builder
->add('name')
->add('tags','collection',array(
'data_class' => 'My\Bundle\Entity\Tags'
)
)
->add('save','submit')
;
I changed data_class to null ( only that ) and I'm getting 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 My\Bundle\Entity\Tags*. You can avoid this error by setting the "data_class" option to "My\Bundle\Entity\Tags" or by adding a view transformer that transforms an instance of class My\Bundle\Entity\Tags to scalar, array or an instance of \ArrayAccess.
I've tried with a transformer, so it looked like this :
$transformer = new TagTransformer($this->entityManager);
$builder
->add(
$builder->create(
'tags','collection',array(
'data_class' => 'My\Bundle\Entity\Tags'
)
)->addModelTransformer($transformer)
);
and transformer:
public function transform($tag)
{
if (null === $tag) {
return "";
}
return $tag->toArray();
}
and changed data_class to null again. What I get:
The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class My\Bundle\Entity\Tags. You can avoid this error by setting the "data_class" option to "My\Bundle\Entity\Tags" or by adding a view transformer that transforms an instance of class My\Bundle\Entity\Tags to scalar, array or an instance of \ArrayAccess.
When I changed data_class to My\Bundle\Entity\Tags
The form's view data is expected to be an instance of class My\Bundle\Entity\Tags, but is a(n) array. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms a(n) array to an instance of My\Bundle\Entity\Tags.
Well.. I mean... wtf? What am I doing wrong? How can I change that?
Edit:
My user entity:
class User
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @ORM\ManyToMany(targetEntity="Tags", cascade={"persist"})
*/
protected $tags;
// methods, etc..
}