2012-03-01 69 views
9

我使用Symfony2的,當我嘗試生成架構($ PHP應用程序/控制檯學說:生成:架構)我得到一個錯誤..Symfony2的錯誤:未找到映射文件命名爲

 

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

我只有2個捆綁在proyect:

  • UserBundle
  • FileBundle

我用U連接FileBundle serBundle與此代碼:

 

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

文件的標題是這樣的:

 

    
    namespace xx\UserBundle\Entity; 

    use Doctrine\ORM\Mapping as ORM; 

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

FileBundle非常相似.. 謝謝!

+0

我想'xxx'和'xx'只是替代,是嗎? – 2012-03-01 23:35:00

+0

是的,對不起, – quique150 2012-03-01 23:57:59

+0

我添加了答案...但它是一個遠射:) – 2012-03-02 00:04:19

回答

0

我想不出爲什麼會發生這種情況,但我會在這裏跳過。

嘗試編輯您的config.ymldoctrine部分應該是這樣的:

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: ~ 

通知的mappings名單上的底部。所有包含「鏈接」的包都包含在這裏。

希望這有助於....

+0

我使用$ php應用程序/控制檯原則:映射:信息 找到1個實體映射在實體管理器默認值: [確定] xx \ FileBundle \ Entity \ File,有什麼想法? – quique150 2012-03-04 14:17:08

4

這是某種奇怪,我說,你正在使用PHPDriver的ORM,而不是AnnotationDriver,因爲在課堂上你的數據庫的信息是在註釋中。

無論如何,如果php app/console doctrine:mapping:info命令僅給出1個實體,這意味着您的其他包含User類的包未加載到app/AppKernel.php文件中。在registerBundles()功能附加線

new xxx\UserBundle\xxxUserBundle(), 

$bundles陣列裝入UserBundle。之後,這個功能應該看起來像這樣:

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'。

希望這會有所幫助。

26

你混合主義的映射格式,你有註釋和資源/配置/學說

至少一個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." 

因此,解決辦法是:

你不能在給定的包中混合不同的Doctrine映射格式。所以要麼爲所有實體使用註釋,要麼爲所有實體使用XML。

+0

這解決了我的問題,它仍然是Symfony 2.1中的有效限制,請參閱symfony.com/doc/2.1/book/doctrine.html#add-mapping-information。謝謝 – 2012-10-27 07:44:20

+0

誠實地謝謝你。這爲我節省了大量的調試時間。我永遠不會再使用自動生成對象 – 2014-11-26 10:16:54

3

我同意@ilanco 100%。另外,解決辦法是刪除任何。在文件夾中的XML文件,例如:

C:\xampp\htdocs\localxyz\src\AppBundle/Resources/config/doctrine/Comment.orm.xml

當您運行這樣的命令創建這些XML文件:

C:\xampp\htdocs\localxyz>php app/console doctrine:mapping:import --force AppBundle xml

阮晉勇。

1

好日子,

雖然我知道這已經年前發佈的,而只是想在這裏發表我的答案,或許可以幫助別人:)

只是單純地清除緩存,它對我的作品雖然

php bin/console cache:clear 

感謝