symfony2传递的参数1必须实现接口Doctrine Collection,给出数组

时间:2015-05-13 13:43:08

标签: forms symfony nested arraycollection

我有一个有三个关系的形式(Obras,FechaObra和HorarioObra)。一个Obra可能有很多FechaObra,一个FechaObra可能有许多HorarioObra。但是我按照symfony.com/doc/current/cookbook/form/form_collections.html中的说法制作了表格,但它给了我这个错误:

Catchable Fatal Error: Argument 1 passed to Acme\ReservasBundle\Entity\FechaObra::setHorariosobra() must implement interface Doctrine\Common\Collections\Collection, array given, called in /var/www/html/grisar/entradas/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 410 and defined

我已经将horariosobra定义为arraycollection,但它一直给我这个错误。

捆绑包的源代码位于:github.com/javiermarcon/tickets/tree/master/src/Acme/ReservasBundle

有谁知道为什么给我这个错误? 感谢

1 个答案:

答案 0 :(得分:1)

从setter方法中删除强类型\Doctrine\Common\Collections\Collection

public function setHorariosobra($horariosobra)
{
    // Be sure to "use" ArrayCollection class

    $this->horariosobra = new ArrayCollection($horariosobra);
    foreach ($horariosobra as $horarioobra) {
        $horarioobra->setObra($this);
    }
}

应该解决问题。请记住,Forms组件无需了解Doctrine - 完全取决于您强制使用实体。因此,提交给setter方法的数据是通用数组而不是Doctrine的{​​{1}}

相关问题