我遇到了問題,我不知道如何解決。我正在為網站上的類別做 CRUD。我們可以有 2 種類別,categorieParent每Categorie一種都有一個 categorieParent.我已經使用了 CRUDmake:form但是當我提交表單時出現以下錯誤:屬性路徑“categorie_parent_id”中給出的“整數或空”類型的預期參數、“App\Entity\CategorieParent”。這是我的實體:類別<?phpnamespace App\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass="App\Repository\CategorieRepository") */class Categorie{ /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $categorie_intitule; /** * @ORM\ManyToOne(targetEntity="App\Entity\CategorieParent", inversedBy="categorie_id") */ private $categorie_parent_id; public function __construct() { $this->categorie_id = new ArrayCollection(); $this->categorie_id_1 = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getCategorieIntitule(): ?string { return $this->categorie_intitule; } public function setCategorieIntitule(string $categorie_intitule): self { $this->categorie_intitule = $categorie_intitule; return $this; } /** * @return Collection|Produit[] */ public function getCategorieId1(): Collection { return $this->categorie_id_1; } public function addCategorieId1(Produit $categorieId1): self { if (!$this->categorie_id_1->contains($categorieId1)) { $this->categorie_id_1[] = $categorieId1; $categorieId1->setCategorieId1($this); } return $this; }
1 回答

慕碼人2483693
TA貢獻1860條經驗 獲得超9個贊
看看這部分:
/**
* @ORM\ManyToOne(targetEntity="App\Entity\CategorieParent", inversedBy="categorie_id")
*/
private $categorie_parent_id;
雖然您的屬性名稱是categorie_parent_id,但它不會返回 ID。Doctrine 將這個領域水化成一個對象。它將返回一個CategorieParent對象(或null)??紤]刪除_id此屬性名稱的一部分,因為它不包含整數而是一個對象。
更新您的方法:
public function getCategorieParentId(): ?CategorieParent
{
return $this->categorie_parent_id;
}
public function setCategorieParentId(?CategorieParent $categorie_parent_id): self
{
$this->categorie_parent_id = $categorie_parent_id;
return $this;
}
- 1 回答
- 0 關注
- 153 瀏覽
添加回答
舉報
0/150
提交
取消