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

1.当我输入数据并单击提交按钮时,我会收到此错误。 错误将显示在下面。

2.submit数据来自contactusnew变量,但是此数据不会插入数据库中。

3.当我在以下两个命令下运行时 -> php bin /控制台学说:schema:update --dump -sql -> php bin /控制台学说:schema:update --force

那么只会在数据库中创建ID,而不会添加密码和地址实体字段名称。

4)但我收到以下错误:

在“ WG \ WGBundle \ Entity \ ContactUsNew#adress”中找不到目标实体WG \ WGBundle \ Entity \ Address。

联系我们新实体

/**
 * @var string
 * @ORM\Column(type="string", unique=false)
 * @Assert\NotBlank(message="Please enter your name.")
 * @Assert\Regex(
 *     pattern="/\d/",
 *     match=false,
 *     message="Your name cannot contain a number"
 * )
 */

protected $name = '';
public function getName() : string {
    return $this->name;
}
/**
 * @var string
 * @ORM\Column(type="string", unique=true)
 * @Assert\NotBlank
 * @Assert\Length(min=4, max=254, minMessage="wg.email.short", maxMessage="wg.email.long")
 * @Assert\Email(mode="strict")
 */
protected $emailid = '';
public function getEmailid() : string {
    return $this->emailid;
}

/**
 * @var string
 * @ORM\Column(type="string", unique=false)
 * @Assert\NotBlank(message="Please enter your mobile phone number")
 * @Assert\Regex(message="This does not appear to be a valid phone number.",pattern="/^(([(]?\d{3}[)]?[-. ]?\d{3}[-. ]?\d{4})$)/")
 */

protected $phonenumber = '';

public function getPhoneNumber() : string {
    return $this->phonenumber;
}

/**
 * @var string
 * @ORM\Column(length=4,type="string", unique=false)
 * @Assert\Length(
 *      min = 5,
 *      max = 50,
 *      minMessage = "Your first name must be at least {{ limit }} characters long",
 *      maxMessage = "Your first name cannot be longer than {{ limit }} characters",
 *      allowEmptyString = false
 * )
 */
protected $message = '';

public function getMessage() : string {
    return $this->message;
}

public function setAdress($adress)
{
    $this->adress = $adress;
}

/**
 * @var \Doctrine\Common\Collections\Collection<int, Adress>
 * @ORM\OneToMany(targetEntity="WG\WGBundle\Entity\Address", mappedBy="contact_us_new", indexBy="id")
 */
protected $adress;
/** @return \Doctrine\Common\Collections\Collection<int, Adress> */
public function getAdress()
{
    return $this->adress;
}


public function __construct()
{

}

/**
 * @param int $id
 */
public function setId($id)
{
    $this->id = $id;
}

/**
 * @param string $name
 */
public function setName($name)
{
    $this->name = $name;
}

/**
 * @param string $emailid
 */
public function setEmailid($emailid)
{
    $this->emailid = $emailid;
}

/**
 * @param string $phonenumber
 */
public function setPhoneNumber($phonenumber)
{
    $this->phonenumber = $phonenumber;
}

/**
 * @param string $message
 */
public function setMessage($message)
{
    $this->message = $message;
}

public function  CreateFromFormData (?ContactUsNewFormData $formDatanew) : self {
    $fromObject = new ContactUsNew();

    if($formDatanew){
        $fromObject->setName($formDatanew->name);
        $fromObject->setEmailid($formDatanew->emailid);
        $fromObject->setPhoneNumber($formDatanew->phonenumber);
        $fromObject->setMessage($formDatanew->message);
    }
    return $fromObject;
}

public function updateCreateFromFormData(?ContactUsNewFormData $formDatanew) : void{

    $this->setName($formDatanew->name);
    $this->setEmailid($formDatanew->emailid);
    $this->setPhoneNumber($formDatanew->phonenumber);
    $this->setMessage($formDatanew->message);
}

地址实体

/**
 * @var int
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @var string
 * @Assert\NotBlank
 * @Assert\Type(type="digit")
 * @Assert\PositiveOrZero
 */
protected $pincode;

/**
 * @var string
 * @Assert\NotBlank
 */
protected $adress;



/**
 * @return int
 */
public function getId()
{
    return $this->id;
}

/**
 * @return mixed
 */
public function getPincode()
{
    return $this->pincode;
}

/**
 * @return mixed
 */
public function getAdress()
{
    return $this->adress;
}

/**
 * @param int $id
 */
public function setId($id)
{
    $this->id = $id;
}

/**
 * @param mixed $pincode
 */
public function setPincode($pincode)
{
    $this->pincode = $pincode;
}

/**
 * @param mixed $adress
 */
public function setAdress($adress)
{
    $this->adress = $adress;
}



public function  CreateFromFormData (?AdressFormTypeData $formDatanew) : self {
        $fromObject = new Adress();

        if($formDatanew){
            $fromObject->setPincode($formDatanew->pincode);
            $fromObject->setAdress($formDatanew->adress);
        }
        return $fromObject;
    }

    public function updateCreateFromFormData(AdressFormTypeData $formDatanew) : void{

        $this->setPincode($formDatanew->pincode);
        $this->setAdress($formDatanew->adress);

    }

** ContactUsNewController **

/**
 *
 * @Route("/contactusnew/", name="contact_us_new", methods={"GET", "POST"})
 */
public function newAction(Request $request): Response
{
    return $this->editContactUsNew($request, null);
}

/**
 *
 * @Route("/list/", name="contact_us_list")
 * Method=({"GET","POST"})
 * 
 */
public function indexAction(): Response
{
    $em = $this->getDoctrine()->getManager();

    $entities = $em->getRepository(ContactUsNew::class)->findAll();


    return $this->render('index.html.twig', [

        'entities' => $entities
    ]);
}

/**
 *
 * @Route("/{id}", name="contact_show", methods="GET")
 */
public function showAction(ContactUsNew $contactusnew): Response
{
    $deleteForm = $this->createDeleteForm($contactusnew);
    // $genForm = $this->createGenForm($contactusnew);
    return $this->render('showrecords.html.twig', [
        'entity' => $contactusnew,
        // 'gen_form' => $genForm->createView(),
        'delete_form' => $deleteForm->createView()
    ]);
}

private function editContactUsNew(Request $request,?ContactUsNew $contactusnew): Response
{

    if(!$contactusnew)
    {
        $contactusnew = new ContactUsNew(null);
    }

    $new = !$contactusnew;


    $dataclass = new ContactUsNewFormData($contactusnew);
    $adress_dto = new AdressFormTypeData ($contactusnew->getAdress());

    $dataclass->setadressdto($adress_dto);

    $form = $this->createForm(ContactUsNewForm::class, $dataclass);

    $form->handleRequest($request);

    if ($form->isSubmitted() && $form->isValid()) {

        $em = $this->getDoctrine()->getManager();

        $adress = new Adress();
        $contactusnew->updateCreateFromFormData($dataclass);
        $adress->updateCreateFromFormData($adress_dto);
        $contactusnew->setAdress($adress);

            $em->persist($contactusnew);

             $em->flush();

        return $this->redirectToRoute('contact_us_list');
    }

    return $this->render('contact_us.html.twig', [
        'new' => $new,

        'form' => $form->createView(),
      $this->createCreateForm($contactusnew)->createView()),
    ]);
}

}

这段代码有什么问题?