Blog

Warning when saving a form collection in Symfony2

16 de febrero de 2012Web

Followed the book and cookbook to the dot, but every time I tried to create a new element in a form collection I got the following error: Warning: spl_object_hash() expects parameter 1 to be object, array given in [...]\vendor\doctrine\lib\Doctrine\ORM\UnitOfWork.php

Well, the problem comes from the fact that Symfony2 form component doesn't turn the new elements into objects but into arrays. This is probably because you forgot to tell it which class the collection form is related to.

It has to be told by setting the data_class, as specified in the Form section of the book: public function getDefaultOptions(array $options) {
    return array( 'data_class' => 'Acme\TaskBundle\Entity\Task' );
}

Hope it helps.

Lo último en el blog


Síguenos en Twitter

Mossaica.es | TEL: 626 113 668 | Email: info@mossaica.es