传递给Doctrine \ Common \ Collections \ ArrayCollection :: __ construct()的参数1必须是数组类型,给定对象,

时间:2016-08-11 15:15:34

标签: php doctrine

我有以下实体类

<?php
namespace EvolisClientRequest\Model\Entities;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Email
{
    /**
     * @var \Ramsey\Uuid\Uuid
     * @ORM\Id
     * @ORM\Column(type="uuid")
     * @ORM\GeneratedValue(strategy="CUSTOM")
     * @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     * @var string
     */
    private $sender;

    /**
     * @ORM\Column(type="string")
     * @var string
     */
    private $subject;

    /**
     * @ORM\Column(type="string")
     * @var string
     */
    private $body;

    /**
     * @ORM\ManyToMany(targetEntity="Request", mappedBy="Email")
     * @var Request
     */

    private $request;

    public function __construct(string $sender, string $subject, string $body,Request $request)
    {
        $this->sender = $expeditor;
        $this->subject = $subject;
        $this->body = $body;
        $this->request = $request;
    }

}

执行以下操作时会出错:

$email = $this->email_dao->create ('srjfjgn@rkgjb.com','fkj','sdfkdjhbf',  new \Doctrine\Common\Collections\ArrayCollection($request_dao));

给出错误的行是:

$email = $this->email_dao->create ('srjfjgn@rkgjb.com','fkj','sdfkdjhbf',  new \Doctrine\Common\Collections\ArrayCollection($request_dao));

1 个答案:

答案 0 :(得分:0)

变量$request_dao似乎是一个对象。

ArrayCollection仅接受array作为构造函数参数。