简体   繁体   English

类AppBundle \\ Entity \\ Tarifa的对象无法转换为字符串

[英]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.

相关问题 类 AppBundle\\Entity\\User 的对象无法转换为字符串 Symfony 3 - Object of class AppBundle\Entity\User could not be converted to string Symfony 3 Symfony - Catchable Fatal Error:类App \\ Entity \\ Question的对象无法转换为字符串 - Symfony - Catchable Fatal Error: Object of class App\Entity\Question could not be converted to string 在Symfony中创建表单时,如何解决“类的对象无法转换为字符串”错误? - How to fix 'Object of class could not be converted to string' error when creating a form in Symfony? SS_HTTPRequest无法转换为字符串 - SS_HTTPRequest could not be converted to a string Python字符串到对象(或类?) - Python string to object (or class?) Symfony2表单构建器添加实体“无法加载类型实体” - Symfony2 Form builder add entity 'Could not load type entity' Symfony2.5.3表单字段“实体”-无法加载类型“实体” - Symfony2.5.3 Form field “entity” - Could not load type “entity” 在 PHP 表单中,字符串输入在提交后被转换为 0 - In PHP form, string input gets converted to 0 after submitting Symfony 2:在一个对象上形成,而不是一个映射的实体 - Symfony 2 : Form on an object, not a mapped Entity symfony实体:在属性/ to_string方法中使用另一个实体属性 - symfony entity : use another entity attribute in a property/to_string method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM