I had a problem saving objects for me:
Catchable Fatal Error: Method My\BusinessBundle\Entity\Type::__toString()
must return a string value in
/var/www/MyBusiness0_1/vendor/doctrine/orm/lib/Doctrine/ORM/ORMInvalidArgumentException.php line 113
It is strange that the __ toString () method is a Type entity!
class Type
{
private $type;
protected $mailTelContacts;
public function __construct()
{
$this->mailTelContacts = new \Doctrine\Common\Collections\ArrayCollection();
}
public function __toString()
{
return $this->getType();
}
Another strange thing: if I put cascade = {"persist"} the MailTelCont class with respect to ManyToOne, the type "type" does not show me this error, but it saves the new field in Type ..
class MailTelCont
class MailTelCont
{
private $contact;
private $type;
private $anagrafica;
public function __toString()
{
return $this->getContact();
}
Call the form of the nested "AnagraficType" as follows:
class TypeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type', 'entity', array(
'class' => 'My\BusinessBundle\Entity\Type',
'attr' => array('class' => 'conct'),
'property' => 'type',
'label' => 'Tipologia',
))
;
}
*****
class MailTelContType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('type', new TypeType())
->add('contact', 'text', array('label' => 'Contatto'))
;
}
*****
class AnagraficaType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('mailTelContacts', 'collection', array('type' => new MailTelContType(),
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'by_reference' => false
))
Where am I doing wrong?