Symfony2错误:找不到映射文件命名 [英] Symfony2 Error: No mapping file found named

查看:97
本文介绍了Symfony2错误:找不到映射文件命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Symfony2,当我尝试生成模式($ php app / console doctrine:generate:schema)时,我收到一个错误..

 

[Doctrine\ORM\Mapping\MappingException]
没有找到名为xxx.UserBundle.Entity.User.php的映射文件,用于'xxx \UserBundle \' Entity\User。

我的Proyect中只有2个包:




  • UserBundle

  • FileBundle



我将FileBundle与UserBundle连接使用以下代码:

 


/ **
* @ ORM\ManyToOne(targetEntity =xxx\UserBundle\Entity\User)
** /
protected $ user;


文件的标题如下所示:

 


命名空间xx\UserBundle\Entity;

使用Doctrine\ORM\Mapping作为ORM;

/ **
* @ ORM\Entity
** /
类用户
{### ... ###}


FileBundle非常相似..
谢谢! p>

解决方案

您正在混合Doctrine映射格式,在Resources / config / doctrine中有注释和至少一个XML文件



从symfony文档:

 一个bundle只能接受一个元数据定义格式。例如,
不可能将YAML元数据定义与注释的PHP
实体类定义进行混合。

所以解决方案是:



你不能在给定的束中混合不同的教义映射格式。所以要么为所有实体使用注释,要么为所有实体使用XML。


I am using Symfony2 and when i try to generate the schema ($ php app/console doctrine:generate:schema) i got an error..


    [Doctrine\ORM\Mapping\MappingException]                                                                             
      No mapping file found named 'xxx.UserBundle.Entity.User.php' for class 'xxx\UserBundle\Entity\User'.

I only have 2 Bundles in the proyect:

  • UserBundle
  • FileBundle

I connect the FileBundle with the UserBundle with this code:


     
    /** 
    * @ORM\ManyToOne(targetEntity="xxx\UserBundle\Entity\User") 
    **/
    protected $user;      
    

The headers of the files are something like this:


    
    namespace xx\UserBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;

    /** 
     * @ORM\Entity
     **/
    class User
    { ###...###}
    

FileBundle is very similar.. Thanks!

解决方案

You are mixing Doctrine mapping formats, you have annotations and at least one XML file in Resources/config/doctrine

From the symfony docs:

"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."

So the solution is:

You cannot mix different Doctrine mapping formats in a given bundle. So either use annotations for all entities or use XML for all.

这篇关于Symfony2错误:找不到映射文件命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆