Symfony2/Doctrine2:生成捆绑包外部的实体


Symfony2/Doctrine2: Generate entities that are outside a bundle

我正在尝试为我的Symfony 2应用程序生成实体。这些实体将由多个捆绑包(可能还有多个应用程序)共享,因此我不希望它们属于一个捆绑包。我希望它们位于 src/MyApp/Entity 文件夹中。

我已经为我的实体提供了YML,存储在src/MyApp/Entity/config/doctrine(class1.orm.yml,...)中。

我正在尝试使用 doctrine:generate:entities 任务生成相应的 PHP 类

这是我在我的应用程序/配置/配置.yml 中的内容

orm:
    auto_generate_proxy_classes: %kernel.debug%
    auto_mapping: false
    mappings: 
      AppRest: 
        type: yml 
        prefix: AppRest'Entity 
        dir: %kernel.root_dir%/../src/AppRest/Entity/config/doctrine

这是我用来生成实体的命令

php app/console doctrine:generate:entities AppRest/Entity

这是我得到的例外

[InvalidArgumentException]
Bundle "AppRest" does not exist or it is not enabled.

我想让教义明白,我不是要生成捆绑的实体。我也尝试指定 --path 选项(--path=src/AppRest/Entity),但它没有改变任何东西。

谁能帮忙?

编辑

我删除了目录中多余的空间,这解决了问题。必须指定路径选项

实际上,我只是在上面的目录选项中缺少一个空格。这现在有效,但我仍然想知道这是否是最好的方法。

使用:

is_bundle: false

更多信息在这里:http://zalas.eu/how-to-store-doctrine-entities-outside-of-a-symfony-bundle/

出现此类错误时,请检查是否指定了捆绑包的快捷方式名称,而不是捆绑包目录的名称。例如,如果您有 Acme''DemoBundle,则它的简称是 AcmeDemoBundle。在这种情况下

orm:
    mappings: 
      DemoBundle: 
          ....

不正确。

正确的是:

orm:
    mappings: 
      AcmeDemoBundle: 
          ....