[英]Object of class AppBundle\Entity\Tarifa could not be converted to string
I saw a lot of similar issues, but I can't find the solution to this without adding __toString() method. 我看到了很多类似的问题,但是在没有添加__toString()方法的情况下我无法找到解决方案。
This works for me: 这对我有用:
$tarifa = new Tarifa();
$form = $this->createForm('AppBundle\Form\TarifaType', $tarifa);
And this does not work... 这不起作用......
$tarifa = new Tarifa();
$peso1 = new TarifaPeso();
$tarifa->addPeso($peso1);
$form = $this->createForm('AppBundle\Form\TarifaType', $tarifa);
Any help is welcome... 欢迎任何帮助......
I believe you need this 我相信你需要这个
$tarifa->addPeso($peso1->getPeso());
or this 或这个
$tarifa->addPeso($peso1->getAmount());
Depending on which property in TarifaPeso you have for this, if its also an entity and have getters 根据TarifaPeso中的哪个属性,如果它也是一个实体并且有吸气剂
or its a ValueObject? 或它的ValueObject?
Configure option choice_label
to be a property from TarifaPeso in your TarifaType class. 将选项
choice_label
配置为TarifaType类中TarifaPeso的属性。 This way, symfony does not intend to convert entity to a string when printing the option label. 这样,symfony不打算在打印选项标签时将实体转换为字符串。 Instead, it will take the property that you point to.
相反,它将采取您指向的属性。
Finally I solved it! 最后我解决了! The fact is I had added the field in the TarifaType that is related to the Collection.
事实是我在TarifaType中添加了与Collection相关的字段。 I removed the field below and now it works!
我删除了下面的字段,现在它的工作原理! Hope it could help anybody... Thanks to all
希望它可以帮助任何人...感谢所有人
->add('tarifa', null, array(
'attr' => array('autofocus' => true),
'label' => 'label.code',
))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.