實際錯誤對於參考: 屬性「category_id」或方法「getCategoryId()」,「categoryId )「,」isCategoryId()「,」hasCategoryId()「,」__get()「存在並且在類」Pas \ ShopTestBundle \ Entity \ Product「中具有公共訪問權限。錯誤:既不是屬性......也沒有一種方法...存在並且具有公共訪問
我已經完成了我對這個錯誤的研究,但是我找不到它。爲什麼我能夠創造'產品'之前,但現在我不能?我看到getCategoryId方法不存在,但不應該有教條創建它們(因爲我確實與教條建立了關係)。
如果我添加屬性CATEGORY_ID我得到錯誤:
在執行時出現異常 'SELECT t0.id AS ID1,AS category_id2,t0.CategoryName AS CategoryName3 FROM類別T0 t0.category_id':
SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列't0.category_id'
有人可以告訴我我做錯了什麼嗎?
關係是很多(產品)對一個(類別)。點擊添加新產品時發生錯誤。在此行中... ... <a class="btn btn-primary" href="{{ path('product_new') }}" role="button">Create a New Entry</a>
導致這個...
{% extends '::base.html.twig' %}
{% block body -%}
<h1>Product creation</h1>
{{ form(form) }}
<ul class="record_actions">
<li>
<a href="{{ path('product') }}">
Back to the list
</a>
</li>
</ul>
{% endblock %}
下面是產品型號:
/* If I move the entity and array to category_id, nothing changes. */
class ProductType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('price')
->add('quantity', 'integer')
->add('category', 'entity', array('class' => 'PasShopTestBundle:Product',
'property' => 'name',
'multiple' => 'true'))
->add('category_id')
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Pas\ShopTestBundle\Entity\Product'
));
}
/**
* @return string
*/
public function getName()
{
return 'pas_shoptestbundle_product';
}
}
產品實體:
<?php
namespace Pas\ShopTestBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Product
*
* @ORM\Table(name="products")
* @ORM\Entity(repositoryClass="Pas\ShopTestBundle\Entity\ProductRepository")
*/
class Product
{
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Description", mappedBy="product")
*/
private $descriptions;
/**
* @var Category
*
* @ORM\ManyToOne(targetEntity="Category", inversedBy="products", fetch="EAGER")
* @ORM\JoinColumn(name="category_id", referencedColumnName="id")
*/
private $category;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var float
*
* @ORM\Column(name="price", type="float")
*/
private $price;
/**
* @var integer
*
* @ORM\Column(name="quantity", type="integer")
*/
private $quantity;
// *
// * @var string
// *
// * @ORM\Column(name="categoryNames", type="string", length=255)
// private $categoryNames;
/**
* Creates Constructer for ArrayCollection
*/
public function __construct() {
$this->descriptions = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Product
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set price
*
* @param float $price
* @return Product
*/
public function setPrice($price)
{
$this->price = $price;
return $this;
}
/**
* Get price
*
* @return float
*/
public function getPrice()
{
return $this->price;
}
/**
* Set Quantity
*
* @param integer $quantity
* @return Product
*/
public function setQuantity($quantity)
{
$this->quantity = $quantity;
return $this;
}
/**
* Get Quantity
*
* @return integer
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* Add descriptions
*
* @param \Pas\ShopTestBundle\Entity\Description $descriptions
* @return Product
*/
public function addDescription(\Pas\ShopTestBundle\Entity\Description $descriptions)
{
$this->descriptions[] = $descriptions;
return $this;
}
/**
* Remove descriptions
*
* @param \Pas\ShopTestBundle\Entity\Description $descriptions
*/
public function removeDescription(\Pas\ShopTestBundle\Entity\Description $descriptions)
{
$this->descriptions->removeElement($descriptions);
}
/**
* Get descriptions
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getDescriptions()
{
return $this->descriptions;
}
/**
* Converts Product Name and Description to a Viewable String
* @return String
*/
public function __toString() {
return $this->getName();
return $this->getDescriptions();
return $this->getCategory();
}
/**
* Set category
*
* @param \Pas\ShopTestBundle\Entity\Category $category
* @return Product
*/
public function setCategory(\Pas\ShopTestBundle\Entity\Category $category = null)
{
$this->category = $category;
return $this;
}
/**
* Get category
*
* @return \Pas\ShopTestBundle\Entity\Category
*/
public function getCategory()
{
return $this->category;
}
}
分類實體:
<?php
namespace Pas\ShopTestBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Category
*
* @ORM\Table(name="categories")
* @ORM\Entity(repositoryClass="Pas\ShopTestBundle\Entity\CategoryRepository")
*/
class Category
{
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Product", mappedBy="category")
*/
private $products;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="CategoryName", type="string", length=255)
*/
private $categoryName;
public function __construct() {
$this->products = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set categoryName
*
* @param string $categoryName
* @return Category
*/
public function setCategoryName($categoryName)
{
$this->categoryName = $categoryName;
return $this;
}
/**
* Get categoryName
*
* @return string
*/
public function getCategoryName()
{
return $this->categoryName;
}
/**
* Add products
*
* @param \Pas\ShopTestBundle\Entity\Product $products
* @return Category
*/
public function addProduct(\Pas\ShopTestBundle\Entity\Product $products)
{
$this->products[] = $products;
return $this;
}
/**
* Remove products
*
* @param \Pas\ShopTestBundle\Entity\Product $products
*/
public function removeProduct(\Pas\ShopTestBundle\Entity\Product $products)
{
$this->products->removeElement($products);
}
/**
* Get products
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProducts()
{
return $this->products;
}
public function __toString() {
return $this->getCategoryName();
return $this->getProducts();
return $this->getCategory();
}
}
和往常一樣幫助是真正appricated,謝謝!
謝謝你,你是對的。將在幾分鐘內接受。 –