symfony2 Catchable Fatal Error: Object of class could not be converted to string symfony2 Catchable Fatal Error: Object of class could not be converted to string symfony symfony

symfony2 Catchable Fatal Error: Object of class could not be converted to string


You need to implement the __toString() method in your Apw\BlackbullBundle\Entity\CategoriesDescription.

You could do:

public function __toString() {    return $this->name;}


For Symfony 3.x

According with Symfony docs v3.x you should use choice_label property to specify the entity field name to be used here.

->add('categoryDescription', 'collection',        array(            'type'         => new CategoriesDescriptionType(),            'allow_add' => true,            'options'      => array('data_class' => 'Apw\BlackbullBundle\Entity\CategoriesDescription'),            'choice_label' => 'name',            'by_reference' => false,        ))


I got the same error but i tweaked it a little bit by adding:

public function __toString() {    return (string) $this->name; }

I'm sure i was getting null instead of a string value. (I was working with sonata-project).