简体   繁体   English

symfony2嵌入式集合编辑表单

[英]symfony2 embedded collection edit form

I created an embedded collection of another entity in a form, the idea would be that when you edit or erase up to 'demand' also would edit the 'products' that belong to it, my creating form is ok, but the editing it gives the error : 我在一个表单中创建了另一个实体的嵌入式集合,其想法是,当您编辑或删除“需求”时也会编辑属于它的“产品”,我的创建表单没问题,但编辑它给出了错误 :

Catchable Fatal Error: Argument 1 passed to MaisAlimentos\\DemandaBundle\\Entity\\Demanda::setProdutosDemanda() must be an instance of Doctrine\\Common\\Collections\\ArrayCollection, instance of Doctrine\\ORM\\PersistentCollection given, called in /var/www/maa/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 347 and defined in /var/www/maa/src/MaisAlimentos/DemandaBundle/Entity/Demanda.php line 130 可捕获致命错误:传递给MaisAlimentos \\ DemandaBundle \\ Entity \\ Demanda :: setProdutosDemanda()的参数1必须是Doctrine \\ Common \\ Collections \\ ArrayCollection的实例,Doctrine \\ ORM \\ PersistentCollection的实例,在/ var / www / maa中调用第347行的/vendor/symfony/src/Symfony/Component/Form/Util/PropertyPath.php,在/var/www/maa/src/MaisAlimentos/DemandaBundle/Entity/Demanda.php第130行中定义

I read on some forums, the solution is remove type of the setter, I got other error: 我在一些论坛上看过,解决方法是删除setter的类型,我得到了其他错误:

Catchable Fatal Error: Object of class Doctrine\\ORM\\PersistentCollection could not be converted to string in /var/www/maa/src/MaisAlimentos/DemandaBundle/Entity/Demanda.php line 136 可捕获致命错误:类Doctrine \\ ORM \\ PersistentCollection的对象无法转换为/var/www/maa/src/MaisAlimentos/DemandaBundle/Entity/Demanda.php第136行中的字符串

my code 我的代码

http://pastebin.com/WeGcHyYL http://pastebin.com/WeGcHyYL

OK, so you've found the solution for your original problem. 好的,所以你找到了原始问题的解决方案。

The second one comes from a typo/copy-paste error. 第二个来自错字/复制粘贴错误。

In the line 162 on your pastebin code: 在您的pastebin代码的第162行:

$this->$produtosDemanda = $produtosDemanda;

should be 应该

$this->produtosDemanda = $produtosDemanda;

So no $ sign after $this-> . 所以在$this->之后没有$符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM