[英]Object of class AppBundle\Entity\User could not be converted to string Symfony 3
[英]Object of class AppBundle\Entity\Tarifa could not be converted to string
我看到了很多類似的問題,但是在沒有添加__toString()方法的情況下我無法找到解決方案。
這對我有用:
$tarifa = new Tarifa();
$form = $this->createForm('AppBundle\Form\TarifaType', $tarifa);
這不起作用......
$tarifa = new Tarifa();
$peso1 = new TarifaPeso();
$tarifa->addPeso($peso1);
$form = $this->createForm('AppBundle\Form\TarifaType', $tarifa);
歡迎任何幫助......
我相信你需要這個
$tarifa->addPeso($peso1->getPeso());
或這個
$tarifa->addPeso($peso1->getAmount());
根據TarifaPeso中的哪個屬性,如果它也是一個實體並且有吸氣劑
或它的ValueObject?
將選項choice_label
配置為TarifaType類中TarifaPeso的屬性。 這樣,symfony不打算在打印選項標簽時將實體轉換為字符串。 相反,它將采取您指向的屬性。
最后我解決了! 事實是我在TarifaType中添加了與Collection相關的字段。 我刪除了下面的字段,現在它的工作原理! 希望它可以幫助任何人...感謝所有人
->add('tarifa', null, array(
'attr' => array('autofocus' => true),
'label' => 'label.code',
))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.