为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 134 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号