Symfony 类型为“整数或空”的预期参数

我遇到了问题,我不知道如何解决。我正在为网站上的类别做 CRUD。

我们可以有 2 种类别,categorieParentCategorie一种都有一个 categorieParent.

我已经使用了 CRUDmake:form但是当我提交表单时出现以下错误:

属性路径“categorie_parent_id”中给出的“整数或空”类型的预期参数、“App\Entity\CategorieParent”。

这是我的实体:

类别

<?php


namespace 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;

    }


一只斗牛犬
浏览 136回答 1
1回答

慕码人2483693

看看这部分:/**&nbsp;* @ORM\ManyToOne(targetEntity="App\Entity\CategorieParent", inversedBy="categorie_id")&nbsp;*/private $categorie_parent_id;虽然您的属性名称是categorie_parent_id,但它不会返回 ID。Doctrine 将这个领域水化成一个对象。它将返回一个CategorieParent对象(或null)。考虑删除_id此属性名称的一部分,因为它不包含整数而是一个对象。更新您的方法:public function getCategorieParentId(): ?CategorieParent{&nbsp; &nbsp; return $this->categorie_parent_id;}public function setCategorieParentId(?CategorieParent $categorie_parent_id): self{&nbsp; &nbsp; $this->categorie_parent_id = $categorie_parent_id;&nbsp; &nbsp; return $this;}
打开App,查看更多内容
随时随地看视频慕课网APP