8

我在我的 symfony 2.3 应用程序中使用了学说。我想使用像这样的文件夹结构

/MyBundleName/User/User.php

对于我的实体。

问题:

无论如何,我是否可以直接将教义 ORM 显式映射为使用显式目录而不是默认为Entity我的 Bundle 的目录?

我想将所有相关文件保存在各自的目录中,ProductProvider例如

/MyBundleName/Product/ProductProvider.php

任何帮助将不胜感激。

4

3 回答 3

14

只是为了跟进@Imanol的正确答案,可以将您的实体放在一个实体管理器下的多个目录中:

doctrine:
  orm:
    default_entity_manager:       default
    auto_generate_proxy_classes: %kernel.debug%

    entity_managers:

        default:
            connection: default
            mappings:

        test01:
            connection: test01
            mappings:
              product:
                type:      yml
                dir:       %kernel.root_dir%/../src/Cerad/Bundle/Test01Bundle/Product
                prefix:    Cerad\Bundle\Test01Bundle\Product
                alias:     Product
                is_bundle: false
              user:
                type:      yml
                dir:       %kernel.root_dir%/../src/Cerad/Bundle/Test01Bundle/User
                prefix:    Cerad\Bundle\Test01Bundle\User
                alias:     User
                is_bundle: false

不要担心 is_bundle: false 条目。实体仍然可以存在于一个包中。教义不在乎。如果您想知道,别名参数可以让您执行以下操作:

$repo = $em->getRepository("Product:Product");
于 2013-08-29T16:01:31.933 回答
4

you can tell Doctrine the directory where is your entities

doctrine:
orm:
    auto_generate_proxy_classes: %kernel.debug%
    auto_mapping: false
    mappings:
        name:
            type: php
            dir: %kernel.root_dir%/../src/Company/CartoDBBundle/Tests/CartoDB/Entity

Here you have the full documentation Doctrine configuration

I made a similar question a few days ago, there you can read the full answer Cedar gave me
Similar post

于 2013-08-29T09:23:03.703 回答
0

我花了一些时间试图找出最简单的情况。这就是我使它工作的方式:

doctrine:
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
        mappings:
            AppBundle:
                mapping: true
                type: annotation
                dir: Model
                alias: AppBundle
                prefix: 'AppBundle\Model'
                is_bundle: true

我只是想将我的实体存储在我的包内名为“模型”的目录中,而不是默认的“实体”。

于 2017-05-11T08:50:44.277 回答