且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Symfony2错误使用doctrine:generate:实体创建Getters和Setters

更新时间:2022-10-14 23:39:49

这是由于新的捆绑包未自动注册在/app/config/config.yml文件中。所以教义不知道在哪里明确寻找实体。



如果只有一个ORM数据库连接,这可能不是问题。但是,如果您使用特殊的ORM映射定义了多个连接,则需要记住使用正确的实体管理器连接注册每个单个捆绑:

  doctrine:
orm:
default_entity_manager:cms
entity_managers:
cms:
connection:cms
mappings:
GutensiteCmsBundle:〜
GutensiteArticleBundle:〜
结算:
连接:计费
映射:
GutensiteBillingBundle:〜

似乎应该有一个更好的方法来让所有实体使用默认的默认,所以你不必每次都这样做。有人知道吗?


I've created several entities in my first bundle without any problems. But when I create a new bundle, using the normal command:

php app/console generate:bundle

This creates a bundle structure with template files and registers the bundle in the app/config/AppKernel.php

I then created entities inside the new bundle folder: /Acme/Bundle/Entity/.

But when I go to generate the getters and setters with the command:

php app/console doctrine:generate:entities AcmeBundle

It gives an error:

[RuntimeException]                                                     
Bundle "AcmeBundle" does not contain any mapped entities. 

Why are these entities not being found?

This was caused by the fact that the new bundle is not automatically registered in the /app/config/config.yml file. So doctrine didn't know where to look for the entities evidently.

Maybe this isn't a problem if you only have one ORM database connection. But if you have defined multiple connections with special ORM mapping, you need to remember to register Every Single Bundle with the right entity manager connection:

doctrine:
    orm:
        default_entity_manager: cms
        entity_managers:
            cms:
                connection: cms
                mappings:
                    GutensiteCmsBundle: ~
                    GutensiteArticleBundle: ~
            billing:
                connection: billing
                mappings:
                    GutensiteBillingBundle: ~

It seems like there should be a better way to have all entities use the default one by... "default" so you don't have to do this every time. Anyone know?