亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Symfony 類型為“整數或空”的預期參數

Symfony 類型為“整數或空”的預期參數

PHP
一只斗牛犬 2021-06-02 10:07:54
我遇到了問題,我不知道如何解決。我正在為網站上的類別做 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;

}


查看完整回答
反對 回復 2021-06-04
  • 1 回答
  • 0 關注
  • 153 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號