该属性和其中一种方法都不存在,并且在课堂上具有公共访问权限

时间:2015-03-02 18:57:09

标签: symfony

在表单中保存数据后,我一直收到以下错误:

  

属性“类别”也不是其中一种方法   “addCategory()”/“removeCategory()”,“setCategories()”,“categories()”,   “__set()”或“__call()”存在并且在课堂上具有公共访问权限   “APW \ BlackbullBundle \实体\产品”。

我有5个表:产品,ProductsDescption,Categories,CategoriesDescription和ProductstoCategories。但我不断收到上述错误。

我有以下表单构建器:

ProductsType:

<?php

namespace Apw\BlackbullBundle\Form;

use Apw\BlackbullBundle\Entity\ProductsDescription;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class ProductsType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('productsDescription', 'collection',
                array(
                    'type' => new ProductsDescriptionType(),
                    'options' => array('data_class' => 'Apw\BlackbullBundle\Entity\ProductsDescription'),
                    'label' => 'Nome prodotto:'
                ))
            ->add('productsQuantity')
            ->add('productsModel')
            ->add('productsImage')
            ->add('productsPrice')
            ->add('productsDateAvailable', 'date', array(
                                                        'input'  => 'datetime',
                                                        'widget' => 'single_text',))
            ->add('productsWeight')
            ->add('productsStatus')
            ->add('categories', 'entity', array(
                                            'class'       => 'ApwBlackbullBundle:CategoriesDescription',
                                            'property'    => 'categoriesName',
                                            'empty_value' => 'Scegliere una categoria',
                                            'required'    => false,
                                            'label'       => 'Crea in:'))
            ->add('productsDescription', 'collection', array(
                                                        'type' => new ProductsDescriptionType(),
                                                        'options' => array('data_class' => 'Apw\BlackbullBundle\Entity\ProductsDescription'),
                                                        'label' => 'Descrizione prodotto:'))
            ->add('salva','submit')
            ->add('azzera','reset')
        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Apw\BlackbullBundle\Entity\Products'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'apw_blackbullbundle_products';
    }
}

我的类别类型:

<?php

namespace Apw\BlackbullBundle\Form;

use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class CategoriesType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('categoryDescription', 'collection',
                array(
                    'type' => new CategoriesDescriptionType(),
                    'allow_add' => true,
                    'options' => array('data_class' => 'Apw\BlackbullBundle\Entity\CategoriesDescription'),
                    'by_reference' => false,
                ))
            //->add('categoriesImage', null, array('label'=>'Foto:'))
            ->add('categoriesStatus', null, array('label'=>'Stato:'))
            ->add('parentId', 'entity', array(
                                            'class'       => 'ApwBlackbullBundle:CategoriesDescription',
                                            'property'    => 'categoriesName',
                                            'empty_value' => 'Scegliere una categoria',
                                            'required'    => false,
                                            'label'       => 'Crea in:'))
            ->add('salva','submit')
            ->add('azzera','reset')
        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Apw\BlackbullBundle\Entity\Categories',
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'categories';
    }
}

类产品

<?php

namespace Apw\BlackbullBundle\Entity;

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

/**
 * Products
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Apw\BlackbullBundle\Entity\ProductsRepository")
 * @ORM\HasLifecycleCallbacks()
 */

class Products
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\Column(name="products_quantity", type="integer", nullable = true)
     */
    private $productsQuantity;

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

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

    /**
     * @var string
     *
     * @ORM\Column(name="products_price", type="decimal", nullable = true)
     */
    private $productsPrice;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="products_date_added", type="datetime", nullable = true)
     */
    private $productsDateAdded;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="products_last_modified", type="datetime", nullable = true)
     */
    private $productsLastModified;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="products_date_available", type="datetime", nullable = true)
     */
    private $productsDateAvailable;

    /**
     * @var string
     *
     * @ORM\Column(name="products_weight", type="decimal", nullable = true)
     */
    private $productsWeight;

    /**
     * @var boolean
     *
     * @ORM\Column(name="products_status", type="boolean", nullable = true)
     */
    private $productsStatus;

    /**
     * @var integer
     *
     * @ORM\Column(name="products_ordered", type="integer", nullable = true)
     */
    private $productsOrdered;

    /**
     * @ORM\OneToMany(targetEntity="ProductsDescription", mappedBy="product")
     */
    private $productsDescription;

    /**
     * @ORM\ManyToMany(targetEntity="Categories", inversedBy="products")
     * @ORM\JoinTable(name="productstocategories")
     */
    private $categories;

    /**
     * @ORM\OneToOne(targetEntity="Manufacturers", inversedBy="products")
     * @ORM\JoinColumn(name="manufacturers_id", referencedColumnName="id")
     **/
    private $manufacturers;

    /**
     * @ORM\OneToMany(targetEntity="ProductsImages", mappedBy="products")
     */
    private $productsImages;


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

    /**
     * Set productsQuantity
     *
     * @param integer $productsQuantity
     * @return Products
     */
    public function setProductsQuantity($productsQuantity)
    {
        $this->productsQuantity = $productsQuantity;

        return $this;
    }

    /**
     * Get productsQuantity
     *
     * @return integer 
     */
    public function getProductsQuantity()
    {
        return $this->productsQuantity;
    }

    /**
     * Set productsModel
     *
     * @param string $productsModel
     * @return Products
     */
    public function setProductsModel($productsModel)
    {
        $this->productsModel = $productsModel;

        return $this;
    }

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

    /**
     * Set productsImage
     *
     * @param string $productsImage
     * @return Products
     */
    public function setProductsImage($productsImage)
    {
        $this->productsImage = $productsImage;

        return $this;
    }

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

    /**
     * Set productsPrice
     *
     * @param string $productsPrice
     * @return Products
     */
    public function setProductsPrice($productsPrice)
    {
        $this->productsPrice = $productsPrice;

        return $this;
    }

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

    /**
     * Set productsDateAdded
     *
     * @param \DateTime $productsDateAdded
     * @return Products
     */
    public function setProductsDateAdded($productsDateAdded)
    {
        $this->productsDateAdded = $productsDateAdded;

        return $this;
    }

    /**
     * Get productsDateAdded
     *
     * @return \DateTime 
     */
    public function getProductsDateAdded()
    {
        return $this->productsDateAdded;
    }

    /**
     * Set productsLastModified
     *
     * @param \DateTime $productsLastModified
     * @return Products
     */
    public function setProductsLastModified($productsLastModified)
    {
        $this->productsLastModified = $productsLastModified;

        return $this;
    }

    /**
     * Get productsLastModified
     *
     * @return \DateTime 
     */
    public function getProductsLastModified()
    {
        return $this->productsLastModified;
    }

    /**
     * Set productsDateAvailable
     *
     * @param \DateTime $productsDateAvailable
     * @return Products
     */
    public function setProductsDateAvailable($productsDateAvailable)
    {
        $this->productsDateAvailable = $productsDateAvailable;

        return $this;
    }

    /**
     * Get productsDateAvailable
     *
     * @return \DateTime 
     */
    public function getProductsDateAvailable()
    {
        return $this->productsDateAvailable;
    }

    /**
     * Set productsWeight
     *
     * @param string $productsWeight
     * @return Products
     */
    public function setProductsWeight($productsWeight)
    {
        $this->productsWeight = $productsWeight;

        return $this;
    }

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

    /**
     * Set productsStatus
     *
     * @param boolean $productsStatus
     * @return Products
     */
    public function setProductsStatus($productsStatus)
    {
        $this->productsStatus = $productsStatus;

        return $this;
    }

    /**
     * Get productsStatus
     *
     * @return boolean 
     */
    public function getProductsStatus()
    {
        return $this->productsStatus;
    }

    /**
     * Set productsOrdered
     *
     * @param integer $productsOrdered
     * @return Products
     */
    public function setProductsOrdered($productsOrdered)
    {
        $this->productsOrdered = $productsOrdered;

        return $this;
    }

    /**
     * Get productsOrdered
     *
     * @return integer 
     */
    public function getProductsOrdered()
    {
        return $this->productsOrdered;
    }


    /**
     * Set manufacturers
     *
     * @param \Apw\BlackbullBundle\Entity\Manufacturers $manufacturers
     * @return Products
     */
    public function setManufacturers(\Apw\BlackbullBundle\Entity\Manufacturers $manufacturers = null)
    {
        $this->manufacturers = $manufacturers;

        return $this;
    }

    /**
     * Get manufacturers
     *
     * @return \Apw\BlackbullBundle\Entity\Manufacturers 
     */
    public function getManufacturers()
    {
        return $this->manufacturers;
    }

    /**
     * @ORM\PrePersist
     */
    public function setCreatedAtValue()
    {
        $date = new \DateTime();
        $this->productsDateAdded = new \DateTime($date->format('d-m-Y H:i:s'));
    }

    /**
     * Add productsImages
     *
     * @param \Apw\BlackbullBundle\Entity\ProductsImages $productsImages
     * @return Products
     */
    public function addProductsImage(\Apw\BlackbullBundle\Entity\ProductsImages $productsImages)
    {
        $this->productsImages[] = $productsImages;

        return $this;
    }

    /**
     * Remove productsImages
     *
     * @param \Apw\BlackbullBundle\Entity\ProductsImages $productsImages
     */
    public function removeProductsImage(\Apw\BlackbullBundle\Entity\ProductsImages $productsImages)
    {
        $this->productsImages->removeElement($productsImages);
    }

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

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->categories = new ArrayCollection();
        $this->productsImages = new ArrayCollection();
        $this->productsDescription = new ArrayCollection();
    }

    /**
     * Add categories
     *
     * @param \Apw\BlackbullBundle\Entity\Categories $categories
     * @return Products
     */
    public function addCategory(\Apw\BlackbullBundle\Entity\Categories $categories)
    {
        $this->categories[] = $categories;

        return $this;
    }

    /**
     * Remove categories
     *
     * @param \Apw\BlackbullBundle\Entity\Categories $categories
     */
    public function removeCategory(\Apw\BlackbullBundle\Entity\Categories $categories)
    {
        $this->categories->removeElement($categories);
    }

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

    /**
     * Add productsDescription
     *
     * @param \Apw\BlackbullBundle\Entity\ProductsDescription $productsDescription
     * @return Products
     */
    public function addProductsDescription(\Apw\BlackbullBundle\Entity\ProductsDescription $productsDescription)
    {
        $this->productsDescription[] = $productsDescription;

        return $this;
    }

    /**
     * Remove productsDescription
     *
     * @param \Apw\BlackbullBundle\Entity\ProductsDescription $productsDescription
     */
    public function removeProductsDescription(\Apw\BlackbullBundle\Entity\ProductsDescription $productsDescription)
    {
        $this->productsDescription->removeElement($productsDescription);
    }

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

班级类别

<?php

namespace Apw\BlackbullBundle\Entity;

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

/**
 * Categories
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Apw\BlackbullBundle\Entity\CategoriesRepository")
 */
class Categories
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

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

    /**
     * @var integer
     *
     * @ORM\Column(name="parent_id", type="integer", nullable = true, options={"default":0})
     */
    private $parentId;

    /**
     * @var integer
     *
     * @ORM\Column(name="sort_order", type="integer", nullable = true, options={"default":0})
     */
    private $sortOrder;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="date_added", type="datetime", nullable = true)
     */
    private $dateAdded;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="last_modified", type="datetime", nullable = true)
     */
    private $lastModified;

    /**
     * @var boolean
     *
     * @ORM\Column(name="categories_status", type="boolean", nullable = true, options={"default" = 1})
     */
    private $categoriesStatus;

    /**
     * @ORM\OneToMany(targetEntity="CategoriesDescription", mappedBy="category")
     */
    private $categoryDescription;

    /**
     * @ORM\ManyToMany(targetEntity="Products", mappedBy="categories")
     **/
    private $products;

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

    /**
     * Set categoriesImage
     *
     * @param string $categoriesImage
     * @return Categories
     */
    public function setCategoriesImage($categoriesImage)
    {
        $this->categoriesImage = $categoriesImage;

        return $this;
    }

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

    /**
     * Set parentId
     *
     * @param integer $parentId
     * @return Categories
     */
    public function setParentId($parentId)
    {
        $this->parentId = $parentId;

        return $this;
    }

    /**
     * Get parentId
     *
     * @return integer
     */
    public function getParentId()
    {
        return $this->parentId;
    }

    /**
     * Set sortOrder
     *
     * @param string $sortOrder
     * @return Categories
     */
    public function setSortOrder($sortOrder)
    {
        $this->sortOrder = $sortOrder;

        return $this;
    }

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

    /**
     * Set dateAdded
     *
     * @param \DateTime $dateAdded
     * @return Categories
     */
    public function setDateAdded($dateAdded)
    {
        $this->dateAdded = $dateAdded;

        return $this;
    }

    /**
     * Get dateAdded
     *
     * @return \DateTime
     */
    public function getDateAdded()
    {
        return $this->dateAdded;
    }

    /**
     * Set lastModified
     *
     * @param \DateTime $lastModified
     * @return Categories
     */
    public function setLastModified($lastModified)
    {
        $this->lastModified = $lastModified;

        return $this;
    }

    /**
     * Get lastModified
     *
     * @return \DateTime
     */
    public function getLastModified()
    {
        return $this->lastModified;
    }

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->categoryDescription = new \Doctrine\Common\Collections\ArrayCollection();
        $this->products = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Add categoryDescription
     *
     * @param \Apw\BlackbullBundle\Entity\CategoriesDescription $categoryDescription
     * @return Categories
     */
    public function addCategoryDescription(\Apw\BlackbullBundle\Entity\CategoriesDescription $categoryDescription)
    {
        $this->categoryDescription[] = $categoryDescription;

        return $this;
    }

    /**
     * Remove categoryDescription
     *
     * @param \Apw\BlackbullBundle\Entity\CategoriesDescription $categoryDescription
     */
    public function removeCategoryDescription(\Apw\BlackbullBundle\Entity\CategoriesDescription $categoryDescription)
    {
        $this->categoryDescription->removeElement($categoryDescription);
    }

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

    /**
     * Add products
     *
     * @param \Apw\BlackbullBundle\Entity\Products $products
     * @return Categories
     */
    public function addProduct(\Apw\BlackbullBundle\Entity\Products $products)
    {
        $products->addCategory($this);
         $this->products[] = $products;

        return $this;
    }

    /**
     * Remove products
     *
     * @param \Apw\BlackbullBundle\Entity\Products $products
     */
    public function removeProduct(\Apw\BlackbullBundle\Entity\Products $products)
    {
        $this->products->removeElement($products);
    }

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

    /**
     * Set categoriesStatus
     *
     * @param boolean $categoriesStatus
     * @return Categories
     */
    public function setCategoriesStatus($categoriesStatus)
    {
        $this->categoriesStatus = $categoriesStatus;

        return $this;
    }

    /**
     * Get categoriesStatus
     *
     * @return boolean
     */
    public function getCategoriesStatus()
    {
        return $this->categoriesStatus;
    }
}

这是我的CategoriesDescription类:

<?php

namespace Apw\BlackbullBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * CategoriesDescription
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Apw\BlackbullBundle\Entity\CategoriesDescriptionRepository")
 */
class CategoriesDescription
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

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

    /**
    * @ORM\ManyToOne(targetEntity="Categories", inversedBy="categoryDescription")
    **/
    private $category;

    /**
     * @ORM\ManyToOne(targetEntity="Languages", inversedBy="categoriesDescription")
     * @ORM\JoinColumn(name="languages_id", referencedColumnName="id")
     **/
    private $languages;

    public function __toString() {
        return $this->categoriesName;
    }

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

    /**
     * Set categoriesName
     *
     * @param string $categoriesName
     * @return CategoriesDescription
     */
    public function setCategoriesName($categoriesName)
    {
        $this->categoriesName = $categoriesName;

        return $this;
    }

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

    /**
     * Set languages
     *
     * @param \Apw\BlackbullBundle\Entity\Languages $languages
     * @return CategoriesDescription
     */
    public function setLanguages(\Apw\BlackbullBundle\Entity\Languages $languages = null)
    {
        $this->languages = $languages;

        return $this;
    }

    /**
     * Get languages
     *
     * @return \Apw\BlackbullBundle\Entity\Languages 
     */
    public function getLanguages()
    {
        return $this->languages;
    }

    /**
     * Set category
     *
     * @param \Apw\BlackbullBundle\Entity\Categories $category
     * @return CategoriesDescription
     */
    public function setCategory(\Apw\BlackbullBundle\Entity\Categories $category = null)
    {
        $this->category = $category;

        return $this;
    }

    /**
     * Get category
     *
     * @return \Apw\BlackbullBundle\Entity\Categories
     */
    public function getCategory()
    {
        return $this->category;
    }
}

任何想法?哪里错了?

2 个答案:

答案 0 :(得分:4)

我遇到了类似的问题,并且能够通过添加&#39; multiple&#39;来修复它。 =&GT;是的,您还可以选择添加&#39;展开&#39; =&GT;如果您想使用复选框,则为TRUE

&#13;
&#13;
{{1}}
&#13;
&#13;
&#13;

答案 1 :(得分:1)

您在“产品表单类型”中将categories设置为ApwBlackbullBundle:CategoriesDescription

        ->add('categories', 'entity', array(
                                        'class'       => 'ApwBlackbullBundle:CategoriesDescription', // your problem
                                        'property'    => 'categoriesName',
                                        'empty_value' => 'Scegliere una categoria',
                                        'required'    => false,
                                        'label'       => 'Crea in:'))

但您的Product实体使用ApwBlackbullBundle:Categories

/**
 * @ORM\ManyToMany(targetEntity="Categories", inversedBy="products")
 * @ORM\JoinTable(name="productstocategories")
 */
private $categories;

并且是\Apw\BlackbullBundle\Entity\Categories的类型提示:

/**
 * Add categories
 *
 * @param \Apw\BlackbullBundle\Entity\Categories $categories
 * @return Products
 */
public function addCategory(\Apw\BlackbullBundle\Entity\Categories $categories)
{
    $this->categories[] = $categories;

    return $this;
}

/**
 * Remove categories
 *
 * @param \Apw\BlackbullBundle\Entity\Categories $categories
 */
public function removeCategory(\Apw\BlackbullBundle\Entity\Categories $categories)
{
    $this->categories->removeElement($categories);
}

这些需要匹配您的表格才能正常运行。可能的解决方案是将第一个引用的代码段中的'class' => 'ApwBlackbullBundle:CategoriesDescription'更改为'class' => 'ApwBlackbullBundle:Categories'