无法在Symfony2中获取属性或其方法

时间:2015-03-04 09:37:22

标签: php symfony

所以我的问题是,每当我尝试提交表单时,我都会收到这样的错误。我正在尝试将数据保存在数据库中。

Neither the property "catalogId" nor one of the methods "addCatalogId()"/"removeCatalogId()", "setCatalogId()", "catalogId()", "__set()" or "__call()" exist and have public access in class "RetailMapping\Bundle\RetailOutletBundle\Entity\RetailOutlet"

但我确实有catalogId及其getter和setter。但是当我使用public $ catalogId而不是private $ catalogId时,它可以工作。这是我的retailoutlet.php实体。我假设问题源于此处(我删除了一些不相关的代码)。     

namespace RetailMapping\Bundle\RetailOutletBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * RetailOutlet.
 *
 * @ORM\Table(name="retail_outlet")
 * @ORM\Entity(repositoryClass="RetailMapping\Bundle\RetailOutletBundle\Entity\RetailOutletRepository")
 */
class RetailOutlet
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;


    /**
     * @ORM\ManyToMany(targetEntity="RetailMapping\Bundle\CatalogBundle\Entity\Catalog")
     * @ORM\JoinTable(name="retailshop_inventory",
     *     joinColumns={@ORM\JoinColumn(name="retail_outlet_id", referencedColumnName="id")},
     *     inverseJoinColumns={@ORM\JoinColumn(name="catalog_id", referencedColumnName="id")}
     * )
     */
    private $catalogId;

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

    /**
     * Constructor.
     */
    public function __construct()
    {
        $this->retailOutletId = new ArrayCollection();
    }

    /**
     * Add retailOutletId.
     *
     * @param \RetailMapping\Bundle\RetailOutletBundle\Entity\RetailOutlet $retailOutletId
     *
     * @return RetailOutlet
     */
    public function addRetailOutletId(\RetailMapping\Bundle\RetailOutletBundle\Entity\RetailOutlet $retailOutletId)
    {
        $this->retailOutletId[] = $retailOutletId;

        return $this;
    }

    /**
     * Remove retailOutletId.
     *
     * @param \RetailMapping\Bundle\RetailOutletBundle\Entity\RetailOutlet $retailOutletId
     */
    public function removeRetailOutletId(\RetailMapping\Bundle\RetailOutletBundle\Entity\RetailOutlet $retailOutletId)
    {
        $this->retailOutletId->removeElement($retailOutletId);
    }

    /**
     * Get retailOutletId.
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getRetailOutletId()
    {
        return $this->retailOutletId;
    }

    /**
     * Add catalogId.
     *
     * @param \RetailMapping\Bundle\CatalogBundle\Entity\Catalog $catalogId
     *
     * @return RetailOutlet
     */
    public function addCatalogId(\RetailMapping\Bundle\CatalogBundle\Entity\Catalog $catalogId)
    {
        $this->catalogId[] = $catalogId;

        return $this;
    }

    /**
     * Remove catalogId.
     *
     * @param \RetailMapping\Bundle\CatalogBundle\Entity\Catalog $catalogId
     */
    public function removeCatalogId(\RetailMapping\Bundle\CatalogBundle\Entity\Catalog $catalogId)
    {
        $this->catalogId->removeElement($catalogId);
    }

    /**
     * Get catalogId.
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getCatalogId()
    {
        return $this->catalogId;
    }
}

这是我的表格。它在下拉列表中完美地显示了数据库中的数据。

<div class="form-group">
            <label for="retailmapping_bundle_retailoutletbundle_retailoutlet_catalogid"> Catalog Id </label>
            {{ form_widget(form.catalogId, {'attr':{'class':'form-control'}})}}
        </div>

0 个答案:

没有答案