简体   繁体   English

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

[英]Symfony - Could not determine access type for property “id”

I get this error:我收到此错误:

Could not determine access type for property "id"无法确定属性“id”的访问类型

Then I read on the internet that I need to add a set function for id.然后我在网上看到我需要为id添加一个set函数。 But that only led to other errors.但这只会导致其他错误。

<?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;
    }
}

Remove name="id" , or try this construction for you id field.删除name="id" ,或者为您的id字段尝试这种构造。

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

Something like this像这样的东西

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Symfony 4 | ManyToMany关系-无法确定属性的访问类型 - Symfony 4 | ManyToMany Relation - Could not determine access type for property 无法确定 class “App\Entity\XXXX”中属性“image”的访问类型。 Symfony 4 - EasyAdmin 3.2 - VichUploader - Could not determine access type for property “image” in class “App\Entity\XXXX”. Symfony 4 - EasyAdmin 3.2 - VichUploader 对于某些,但不是全部,表单提交得到“无法确定属性的访问类型”id“。” - for some, but not all, form submission got “Could not determine access type for property ”id“.” 使用EntityType表单构建器时,Symfony无法确定访问类型 - Symfony Could not determine access type when using EntityType form builder 将&#39;by reference&#39;设置为false,在symfony表单上抛出&#39;无法确定访问类型&#39; - setting 'by reference' to false, on symfony form throws 'Could not determine access type' 无法确定访问类型 - Could not determine access type 在类“ App \\ Entity \\ GameGenre”中无法确定属性“游戏”的访问类型: - Could not determine access type for property “games” in class “App\Entity\GameGenre”: 无法在symfony中加载类型 - Could not load type in symfony 在Symfony中按ID访问项目? - Access Item By Id in Symfony? 无法加载类型提交symfony 3 - could not load type submit symfony 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM