Doctrine Symfony2错误:未找到名为的映射文件
我使用的是Symfony2,当我试图生成模式($php应用程序/控制台原则:generate:schema)时,我得到了一个错误 [Doctrine\ORM\Mapping\MappingException] No mapping file found named 'xxx.UserBundle.Entity.User.php' for class 'xxx\UserBundle\Entity\User'. 文件的标题如下所示:Doctrine Symfony2错误:未找到名为的映射文件,doctrine,symfony,mapping,entity,Doctrine,Symfony,Mapping,Entity,我使用的是Symfony2,当我试图生成模式($php应用程序/控制台原则:generate:schema)时,我得到了一个错误 [Doctrine\ORM\Mapping\MappingException] No mapping file found named 'xxx.UserBundle.Entity.User.php' f
doctrine:
dbal:
default_connection: my_connection_name
connections:
fmefb:
host: %database_host%
dbname: %database_name%
user: %database_user%
password: %database_password%
driver: %database_driver%
port: %database_port%
charset: UTF8
orm:
default_entity_manager: my_entity_manager
entity_managers:
my_entity_manager:
connection: my_connection_name
mappings:
CompanyNameSiteBundle: ~
CompanyNameAdminBundle: ~
CompanyNameSomethingElse: ~
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new xx\FileBundle\xxFileBundle(),
new xxx\UserBundle\xxxUserBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
名称空间xx\UserBundle\Entity;
使用条令\ORM\Mapping作为ORM;
/**
*@ORM\Entity
**/
类用户
{ ###...###}
FileBundle非常相似。。
谢谢 我想不出发生这种情况的原因,但我会在这里跳一跳 尝试编辑您的
config.yml
<代码>条令部分应如下所示:
doctrine:
dbal:
default_connection: my_connection_name
connections:
fmefb:
host: %database_host%
dbname: %database_name%
user: %database_user%
password: %database_password%
driver: %database_driver%
port: %database_port%
charset: UTF8
orm:
default_entity_manager: my_entity_manager
entity_managers:
my_entity_manager:
connection: my_connection_name
mappings:
CompanyNameSiteBundle: ~
CompanyNameAdminBundle: ~
CompanyNameSomethingElse: ~
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new xx\FileBundle\xxFileBundle(),
new xxx\UserBundle\xxxUserBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
注意底部的映射
列表。此处包括“链接”的所有捆绑包
希望这能有所帮助……对于我来说,使用PHPDriver进行ORM而不是AnnotationDriver有点奇怪,因为类中的数据库信息在annotations中 无论如何,if
php-app/console-doctor:mapping:info
命令只提供1个实体,这意味着包含用户类的另一个包没有加载到app/AppKernel.php文件中。通过添加行来加载您的UserBundle
new xxx\UserBundle\xxxUserBundle(),
到registerBundles()
函数中的$bundles
数组。之后,此函数应如下所示:
doctrine:
dbal:
default_connection: my_connection_name
connections:
fmefb:
host: %database_host%
dbname: %database_name%
user: %database_user%
password: %database_password%
driver: %database_driver%
port: %database_port%
charset: UTF8
orm:
default_entity_manager: my_entity_manager
entity_managers:
my_entity_manager:
connection: my_connection_name
mappings:
CompanyNameSiteBundle: ~
CompanyNameAdminBundle: ~
CompanyNameSomethingElse: ~
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new xx\FileBundle\xxFileBundle(),
new xxx\UserBundle\xxxUserBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
当然,把“xx”和“xxx”改成你的真名
希望这有帮助。您正在混合条令映射格式,在参考资料/config/doctor中有注释和至少一个XML文件 从symfony文档:
"A bundle can accept only one metadata definition format. For example,
it's not possible to mix YAML metadata definitions with annotated PHP
entity class definitions."
因此,解决方案是:
您不能在给定的捆绑包中混合不同的条令映射格式。所以要么对所有实体使用注释,要么对所有实体使用XML。我同意@ilanco 100%。此外,解决方案是删除文件夹中的任何.xml文件,例如: C:\xampp\htdocs\localxyz\src\AppBundle/Resources/config/doctor/Comment.orm.xml 运行此命令时创建的这些xml文件: C:\xampp\htdocs\localxyz>php应用程序/控制台原则:映射:导入——强制AppBundle xml 粪。你好 虽然我知道这是多年前发布的,但我只想在这里发布我的答案,也许它可以帮助某人:) 只是简单地清除缓存,但它对我有效
php bin/console cache:clear
谢谢我假设
xxx
和xx
只是替换,是吗?我添加了答案。。。但这很难做到:)我使用$php应用程序/控制台原则:映射:信息在实体管理器默认值中找到1个映射的实体:[确定]xx\FileBundle\entity\File,有什么想法吗?这解决了我的问题,它仍然是Symfony 2.1中的有效限制,请参见Symfony.com/doc/2.1/book/doctor.html#添加映射信息。真的谢谢你。这节省了我大量的调试时间。我将不再使用自动生成对象