我有一个上传文件,我想从那里显示数据库中的所有类别,但我一直收到 EntityType 错误,我不知道之前为什么工作。
这是错误: Cannot assign Doctrine\ORM\PersistentCollection to property App\Entity\Category::$posts of type Doctrine\Common\Collections\ArrayCollection
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CategoryRepository::class)
*/
class Category
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private int $id;
/**
* @ORM\Column(type="string", length=255)
*/
private string $name;
/**
* @ORM\OneToMany(targetEntity=Post::class, mappedBy="Category_id")
*/
private ArrayCollection $Posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function …
Run Code Online (Sandbox Code Playgroud)