我有一個問題,試圖從Symfony2.1項目中使用Doctrine2從表(通過實體)獲取數據。這裏是我的錯誤控制器:Symfony2.1映射錯誤:class_parents()
/**
* Country list
*/
public function countrylistAction()
{
$em = $this->getDoctrine()->getManager();
$countryList = $em->getRepository('ProjectBaseBundle:SYS_TCountry')
->findAll();
$serializer = new Serializer(array(new GetSetMethodNormalizer()),
array('json' => new JsonEncoder()));
return new Response($serializer->serialize($countryList, 'json'));
}
實體:
<?php
namespace Company\Project\BaseBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="SYS_TCountry")
*/
class SYS_TCountry
{
/**
* @ORM\Id
* @ORM\Column(type="string", length=3, nullable=false)
* @var string
*/
protected $idcountry;
/**
* @ORM\Column(type="string", length=75, nullable=false)
* @Assert\NotBlank()
* @var string
*/
protected $name;
....
public function getIdcountry() { return $this->idcountry; }
public function getName() { return $this->name; }
public function getA2() { return $this->a2; }
public function getA3() { return $this->a3; }
public function getIdstatus() { return $this->idstatus; }
public function setIdcountry($idcountry) { $this->idcountry = $idcountry; }
public function setName($name) { $this->name = $name; }
public function setA2($a2) { $this->a2 = $a2; }
public function setA3($a3) { $this->a3 = $a3; }
public function setIdstatus($idstatus) { $this->idstatus = $idstatus; }
public function __toString() { return $this->idcountry; }
}
Config.yml:
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
這是錯誤:
Warning: class_parents():
Class Company\Project\BaseBundle\Entity\SYS_TCountry does not exist and could not be loaded in
/var/www/project/src/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php line 40
這很奇怪,因爲正如學說所言控制檯,映射做得好:我測試了執行PHP應用程序/控制檯學說:映射:信息:
[OK] Company\Project\BaseBundle\Entity\SYS_TCountry
,如果我在控制檯執行查詢一切順利 - >應用程序/控制檯學說:查詢:sql'SELECT * FROM SYS_TCountry',返回結果。
我不知道是否使用Symfony2.1我必須配置與2.0版本不同的東西,但似乎相同,因爲映射是Doctrine責任。
你在config.yml中'orm'節的配置是什麼?你可以把它附在你的問題上嗎? – 2012-07-27 13:50:25
是的,我已將它附加在消息中,但是是默認設置。在另一個具有相同配置的Symfony2項目中,一切都很完美 – unairoldan 2012-07-27 14:13:40
也許,您還必須在配置中手動設置映射嗎? http://symfony.com/doc/current/reference/configuration/doctrine.html – 2012-07-27 14:21:38