想知道是否有其他人遇到過這個問題。總之,我們從Symfony 2.0升級到Symfony 2.1。在Symfony 2.1中,如果創建了一個全新的捆綁包,然後是一個與Doctrine一起使用的實體,我會得到一個"not a valid entity or mapped super class"
。如果我將相同的確切實體類(具有正確的路徑更改)放入現有的包(在2.1之前創建)中,即使從新包中也可以毫無問題地訪問它。Symfony 2.1新創建包中的學說
以下是這些步驟。
$ php app/console generate:bundle --namespace="Core/TestBundle"--format=yml --no-interaction --structure=no --dir=src
$ php app/console doctrine:generate:entity --entity="CoreTestBundle:Product" --fields="name:string(255) price:float description:text"
這裏是Product.php代碼產生
<?php
namespace Core\TestBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Core\TestBundle\Entity\Product
*
* @ORM\Table()
* @ORM\Entity
*/
class Product
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var float $price
*
* @ORM\Column(name="price", type="float")
*/
private $price;
/**
* @var text $description
*
* @ORM\Column(name="description", type="text")
*/
private $description;
/**
* 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 description
*
* @param text $description
* @return Product
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return text
*/
public function getDescription()
{
return $this->description;
}
}
從這裏運行
$ php app/console doctrine:generate:entities "Core/TestBundle/Entity/Product"
或從代碼訪問產品運行到運行
[Doctrine\ORM\Mapping\MappingException] Class Core\TestBundle\Entity\Product is not a valid entity or mapped super class.
$ php app/console doctrine:schema:update --force
產生「無更新「
在另一方面,如果我使用一個現有的預束如ArticleBundle並運行相同的命令,即
$ php app/console doctrine:generate:entity --entity="CoreArticleBundle:Product" --fields="name:string(255) price:float description:text"
$ php app/console doctrine:generate:entities "Core/ArticleBundle/Entity/Product"
$ php app/console doctrine:schema:update --force
創建表細 此外,訪問來自TestBundle產品爲CoreArticleBundle:Product
工作正常。 我試圖比較捆綁配置等,但不能拿出任何東西。
我也運行db創建腳本如下。
$ php app/console doctrine:database:drop --force
刪除的數據庫名爲dev的連接
$ php app/console doctrine:database:create
創建的數據庫連接名爲dev的除了產品的一個 所有表得到了創建。
另外,我創建與產品對象的常客。一樣。在現有捆綁包中工作。在新創建的包中,與上面相同的錯誤。
如果您不運行schema:update,那麼出現錯誤是正常的。奇怪的是schema:update產生「沒有更新」。你是否檢查過實體是否真的被創建並且它看起來好?你有沒有嘗試過運行教條:schema:create?那「從這裏跑步」是什麼? –
你能否在php應用/控制檯原則之後粘貼生成的Product實體的代碼:generate:entity --entity =「CoreTestBundle:Product」--fields =「name:string(255)price:float description:text」? – Sybio
這裏是Product.php代碼 – Victor