微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Symfony主义未定义索引

如何解决Symfony主义未定义索引

我正在尝试使用联接查询来进行主义查询。 我已经做了以下事情:

    public function getCategoriesFromCategorieParentAndConstructeur(): ?Array
    {
        return $this->createqueryBuilder('c')
            ->leftJoin('c.categorie_parent_id','cp' )
            ->getQuery()
            ->getResult();
    }

但是当我尝试显示结果时,出现以下错误

注意:未定义索引:类别

我不知道你为什么还能告诉我更多信息?

这是我的2个实体 : 分类实体

/**
 * @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;


    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\User",inversedBy="categories")
     */
    private $created_by;

    /**
     * @ORM\OnetoMany(targetEntity="App\Entity\Produit",mappedBy="categorie_id",orphanRemoval=true)
     */
    private $produits;

CategorieParent实体

    /**
     * @ORM\OnetoMany(targetEntity="App\Entity\Categorie",mappedBy="categorie_parent_id",cascade={"remove"})
     */
    private $categorie_id;

    public function __construct()
    {
        $this->categorie_id = 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;
    }

谢谢你

解决方法

您可以按照本通知的内容在用户实体中定义变量$categories,该变量可能为:

/**
 * @ORM\OneToMany(targetEntity=App\Entity\Categorie,mappedBy="created_by")
 */
private $categories;

这应该是最好的选择,因为它将为您提供数据库和实体之间的正确映射。

否则,您只能disable notice reporting

<?php
    error_reporting(E_ERROR | E_WARNING | E_PARSE); 
?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?