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

时间:2021-04-24 06:45:44

I'm trying to generate entities for my Symfony 2application. The entities will be shared by several bundles (and maybe several applications), and thus I do not want them to belong to a bundle. I want them to be in the src/MyApp/Entity folder.

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

I already have the YML for my entities, stored in src/MyApp/Entity/config/doctrine (class1.orm.yml, ...)

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

I'm trying to generate the corresonding PHP classes using the doctrine:generate:entities task

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

Here is what I have in my app/config/config.yml

这是我在app / config / config.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

Here is the command I use to generate the entities

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

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

Here is the exception I get

这是我得到的例外

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

I want to make doctrine understand that I'm not trying to generate entities tha are in a bundle. I also tried specifying the --path option (--path=src/AppRest/Entity), but it did not change anything.

我想让学说理解我并不是想要生成实体。我也尝试指定--path选项(--path = src / AppRest / Entity),但它没有改变任何东西。

Can anyone help ?

有人可以帮忙吗?

Edit:

编辑:

I removed the extra space in my dir, which solved the problem. The path option must be specified

我删除了我的目录中的额外空间,这解决了问题。必须指定path选项

3 个解决方案

#1


3  

Actually, I was just missing a space in my dir option above. This works now, but I'm still wondering whether that's the best way to go.

实际上,我在上面的dir选项中错过了一个空格。这现在有效,但我仍然想知道这是否是最佳方式。

#2


1  

Use:

使用:

is_bundle: false

More info here: http://zalas.eu/how-to-store-doctrine-entities-outside-of-a-symfony-bundle/

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

#3


-1  

When you have such error, check if you specified the shortcut name of the bundle, not the name of the bundle directory. For example, if you have Acme\DemoBundle the shortname of it is AcmeDemoBundle. In this case

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

orm:
    mappings: 
      DemoBundle: 
          ....

is INCORRECT.

是不正确的。

the correct is:

正确的是:

orm:
    mappings: 
      AcmeDemoBundle: 
          ....

#1


3  

Actually, I was just missing a space in my dir option above. This works now, but I'm still wondering whether that's the best way to go.

实际上,我在上面的dir选项中错过了一个空格。这现在有效,但我仍然想知道这是否是最佳方式。

#2


1  

Use:

使用:

is_bundle: false

More info here: http://zalas.eu/how-to-store-doctrine-entities-outside-of-a-symfony-bundle/

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

#3


-1  

When you have such error, check if you specified the shortcut name of the bundle, not the name of the bundle directory. For example, if you have Acme\DemoBundle the shortname of it is AcmeDemoBundle. In this case

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

orm:
    mappings: 
      DemoBundle: 
          ....

is INCORRECT.

是不正确的。

the correct is:

正确的是:

orm:
    mappings: 
      AcmeDemoBundle: 
          ....