给定类型...,“ Doctrine \ Common \ Collections \ ArrayCollection”的预期参数

时间:2018-09-11 15:15:26

标签: php symfony doctrine-orm sonata-admin symfony4

因此,我正在做一个表单来保存属性,并且该属性需要链接到网站。当我尝试保存属性时,出现以下错误:给出类型为“ App \ Entity \ Website”,“ Doctrine \ Common \ Collections \ ArrayCollection”的预期参数。

这是2个实体和控制器的代码。

Website.php

std::vector

Attribute.php     

<?php

namespace App\Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\WebsiteRepository")
 */
class Website
{
/**
 * @ORM\Id()
 * @ORM\GeneratedValue()
 * @ORM\Column(type="integer")
 */
private $id;

/**
 * @ORM\Column(type="string", length=255)
 */
private $slug;

/**
 * @ORM\Column(type="string", length=255)
 */
private $name;

/**
 * @var \DateTime $created_at
 * @Gedmo\Timestampable(on="create")
 * @ORM\Column(type="datetime")
 */
private $created_at;

/**
 * @var \DateTime $updated_at
 * @Gedmo\Timestampable(on="update")
 * @ORM\Column(type="datetime")
 */
private $updated_at;

/**
 * @var \DateTime $contentChanged
 *
 * @ORM\Column(name="content_changed", type="datetime", nullable=true)
 * @Gedmo\Timestampable(on="change", field={"slug", "name"})
 */
private $contentChanged;

public function __construct() {
    $this->attribute = new \Doctrine\Common\Collections\ArrayCollection();
}

public function getId(): ?int
{
    return $this->id;
}

public function getSlug(): ?string
{
    return $this->slug;
}

public function setSlug(string $slug): self
{
    $this->slug = $slug;

    return $this;
}

public function getName(): ?string
{
    return $this->name;
}

public function setName(string $name): self
{
    $this->name = $name;

    return $this;
}

public function getCreatedAt(): ?\DateTimeInterface
{
    return $this->created_at;
}

public function setCreatedAt(?\DateTimeInterface $created_at): self
{
    $this->created_at = $created_at;

    return $this;
}

public function getUpdatedAt(): ?\DateTimeInterface
{
    return $this->updated_at;
}

public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
    $this->updated_at = $updated_at;

    return $this;
}

public function getContentChanged()
{
    return $this->contentChanged;
}

public function __toString()
{
    return ($this->getName()) ? $this->getName() : '';
}
}

AttributeAdmin.php     

namespace App\Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\AttributeRepository")
 */
class Attribute
{
/**
 * @ORM\Id()
 * @ORM\GeneratedValue()
 * @ORM\Column(type="integer")
 */
private $id;

/**
 * Many Attibute have Many Website.
 * @ORM\ManyToMany(targetEntity="Attribute")
 * @ORM\JoinTable(name="attribute_website",
 *      joinColumns={@ORM\JoinColumn(name="attribute_id", referencedColumnName="id")},
 *      inverseJoinColumns={@ORM\JoinColumn(name="website_id", referencedColumnName="id")}
 *      )
 */
private $website;

/**
 * @ORM\Column(type="string", length=255)
 */
private $slug;

/**
 * @ORM\Column(type="string", length=255)
 */
private $name;

/**
 * @ORM\Column(type="string", length=255)
 */
private $type;

/**
 * @ORM\Column(type="integer", nullable=true)
 */
private $is_master_attribute;

/**
 * @ORM\Column(type="text", nullable=true)
 */
private $options;

/**
 * @ORM\Column(type="string", length=255, nullable=true)
 */
private $prefix;

/**
 * @var \DateTime $created_at
 * @Gedmo\Timestampable(on="create")
 * @ORM\Column(type="datetime")
 */
private $created_at;

/**
 * @var \DateTime $updated_at
 * @Gedmo\Timestampable(on="update")
 * @ORM\Column(type="datetime")
 */
private $updated_at;

/**
 * @var \DateTime $contentChanged
 *
 * @ORM\Column(name="content_changed", type="datetime", nullable=true)
 * @Gedmo\Timestampable(on="change", field={"slug", "name", "type", "is_master_attribute", "options", "prefix"})
 */
private $contentChanged;

public function getId(): ?int
{
    return $this->id;
}

public function getWebsite(): ?Website
{
    return $this->website;
}

public function setWebsite(Website $website): self
{
    $this->website = $website;

    return $this;
}

public function getSlug(): ?string
{
    return $this->slug;
}

public function setSlug(string $slug): self
{
    $this->slug = $slug;

    return $this;
}

public function getName(): ?string
{
    return $this->name;
}

public function setName(string $name): self
{
    $this->name = $name;

    return $this;
}

public function getType(): ?string
{
    return $this->type;
}

public function setType(string $type): self
{
    $this->type = $type;

    return $this;
}

public function getIsMasterAttribute(): ?int
{
    return $this->is_master_attribute;
}

public function setIsMasterAttribute(?int $is_master_attribute): self
{
    $this->is_master_attribute = $is_master_attribute;

    return $this;
}

public function getOptions(): ?string
{
    return $this->options;
}

public function setOptions(?string $options): self
{
    $this->options = $options;

    return $this;
}

public function getPrefix(): ?string
{
    return $this->prefix;
}

public function setPrefix(?string $prefix): self
{
    $this->prefix = $prefix;

    return $this;
}

public function getCreatedAt(): ?\DateTimeInterface
{
    return $this->created_at;
}

public function setCreatedAt(?\DateTimeInterface $created_at): self
{
    $this->created_at = $created_at;

    return $this;
}

public function getUpdatedAt(): ?\DateTimeInterface
{
    return $this->updated_at;
}

public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
    $this->updated_at = $updated_at;

    return $this;
}

public function getContentChanged()
{
    return $this->contentChanged;
}

public function __toString()
{
    return ($this->getName()) ? $this->getName() : '';
}
}

我应该怎么做才能将属性保存到选定的网站?

谢谢

0 个答案:

没有答案