原则映射无法正常工作
Doctrine mapping dont working properly
我在 doctrine mapped superclass 方面遇到问题。
当我执行 symfony 命令时:
php app/console doctrine:mapping:info
我收到这条异常信息:
[Doctrine\Common\Persistence\Mapping\MappingException]
Class 'DBiagi\EitaBundle\Entity\BaseFoo' does not exist
奇怪的是BaseFooclass不在Entity文件夹中,而这个class是映射的superclass。
这是我的文件:
<?php
# src/DBiagi/EitaBundle/Model/BaseFoo.php
namespace DBiagi\EitaBundle\Model;
/**
* Description of BaseFoo
*
*/
abstract class BaseFoo implements BaseFooInterface{
private $id;
private $name;
public function getId(){
return $this->id;
}
public function getName(){
return $this->name;
}
}
映射定义:
# src/DBiagi/EitaBundle/Resources/doctrine/BaseFoo.orm.yml
DBiagi\EitaBundle\Model\BaseFoo:
type: mappedSuperclass
fields:
id:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: 255
请注意 class DBiagi\EitaBundle\Entity\BaseFoo 实际上并不存在,而 BaseFoo class 存在于模型文件夹中,所以问题是:为什么 doctrine 试图加载这个class?由于此异常,我无法映射我的实体。
非常感谢您的帮助。谢谢
您应该在主应用配置中为您的包的实体设置正确的命名空间。假设你使用 yml 配置,smth like:
orm:
entity_managers:
default:
mappings:
DBiagiEitaBundle:
prefix: DBiagi\EitaBundle\Model
我在 doctrine mapped superclass 方面遇到问题。 当我执行 symfony 命令时:
php app/console doctrine:mapping:info
我收到这条异常信息:
[Doctrine\Common\Persistence\Mapping\MappingException] Class 'DBiagi\EitaBundle\Entity\BaseFoo' does not exist
奇怪的是BaseFooclass不在Entity文件夹中,而这个class是映射的superclass。 这是我的文件:
<?php
# src/DBiagi/EitaBundle/Model/BaseFoo.php
namespace DBiagi\EitaBundle\Model;
/**
* Description of BaseFoo
*
*/
abstract class BaseFoo implements BaseFooInterface{
private $id;
private $name;
public function getId(){
return $this->id;
}
public function getName(){
return $this->name;
}
}
映射定义:
# src/DBiagi/EitaBundle/Resources/doctrine/BaseFoo.orm.yml
DBiagi\EitaBundle\Model\BaseFoo:
type: mappedSuperclass
fields:
id:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: 255
请注意 class DBiagi\EitaBundle\Entity\BaseFoo 实际上并不存在,而 BaseFoo class 存在于模型文件夹中,所以问题是:为什么 doctrine 试图加载这个class?由于此异常,我无法映射我的实体。 非常感谢您的帮助。谢谢
您应该在主应用配置中为您的包的实体设置正确的命名空间。假设你使用 yml 配置,smth like:
orm:
entity_managers:
default:
mappings:
DBiagiEitaBundle:
prefix: DBiagi\EitaBundle\Model