【问题标题】:Symfony - Could not determine access type for property "id"Symfony - 无法确定属性“id”的访问类型
【发布时间】:2023-03-24 00:56:01
【问题描述】:

我收到此错误:

无法确定属性“id”的访问类型

然后我在网上看到我需要为 id 添加一个 set 函数。但这只会导致其他错误。

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Product
 *
 * @ORM\Table(name="product")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository")
 */
class Product
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var int
     *
     * @ORM\ManyToOne(targetEntity="Categorie", inversedBy=”producten”)
     * @ORM\JoinColumn(name="categorie", referencedColumnName="id")
     */
    private $categorie;

    /**
     * @var string
     *
     * @ORM\Column(name="naam", type="string", length=100, nullable=true)
     */
    private $naam;

    /**
     * @var string
     *
     * @ORM\Column(name="merk", type="string", length=100, nullable=true)
     */
    private $merk;

    /**
     * @var string
     *
     * @ORM\Column(name="inkoopprijs", type="decimal", precision=10, scale=2, nullable=true)
     */
    private $inkoopprijs;


    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set categorie
     *
     * @param integer $categorie
     *
     * @return Product
     */
    public function setCategorie($categorie)
    {
        $this->categorie = $categorie;

        return $this;
    }

    /**
     * Get categorie
     *
     * @return int
     */
    public function getCategorie()
    {
        return $this->categorie;
    }

    /**
     * Set naam
     *
     * @param string $naam
     *
     * @return Product
     */
    public function setNaam($naam)
    {
        $this->naam = $naam;

        return $this;
    }

    /**
     * Get naam
     *
     * @return string
     */
    public function getNaam()
    {
        return $this->naam;
    }

    /**
     * Set merk
     *
     * @param string $merk
     *
     * @return Product
     */
    public function setMerk($merk)
    {
        $this->merk = $merk;

        return $this;
    }

    /**
     * Get merk
     *
     * @return string
     */
    public function getMerk()
    {
        return $this->merk;
    }

    /**
     * Set inkoopprijs
     *
     * @param string $inkoopprijs
     *
     * @return Product
     */
    public function setInkoopprijs($inkoopprijs)
    {
        $this->inkoopprijs = $inkoopprijs;

        return $this;
    }

    /**
     * Get inkoopprijs
     *
     * @return string
     */
    public function getInkoopprijs()
    {
        return $this->inkoopprijs;
    }
}

【问题讨论】:

  • 请显示导致您的错误的代码。
  • 您应该添加错误的完整堆栈跟踪以及它出现的位置/时间。另请阅读how do I ask a good question?
  • 您可以尝试使用app_dev.php URL 作为described here 来查看是否可以像@gp_sflover 要求的那样获得堆栈跟踪?它可能会帮助您了解问题所在。
  • @gp_sflover 跟踪毫无意义。类似于:“/var/www/cheapmarina/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php:498”、“/var/www/cheapmarina/vendor/sonata-project/admin-bundle/ src/Controller/CRUDController.php:336",之前是HttpKernel.php,之后是PropertyAccessor
  • @gp_sflover 与 AppBundle 或任何其他用户代码无关 =\

标签: php symfony doctrine entity


【解决方案1】:

删除name="id",或为您尝试此构造id 字段。

/**
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

【讨论】:

  • 感谢您的回答。但它是这样的:inversedBy=”producten”。我有复制/粘贴它,但它必须是 inversedBy="producten"
【解决方案2】:

类似的东西

/**
 * Fake
 *
 * @see fabien good guy
 */
public function setId($id) {}

【讨论】:

    猜你喜欢
    • 2019-07-25
    • 2017-05-03
    • 2021-05-07
    • 1970-01-01
    • 2019-09-26
    • 2021-09-19
    • 2020-11-07
    • 2023-03-20
    • 1970-01-01
    相关资源
    最近更新 更多