如何更改symfony 2 doctrine mapper以使用我的自定义目录,而不是我的实体目录下的bundle [英] How do I change symfony 2 doctrine mapper to use my custom directory instead of my Entity Directory under the bundle

查看:135
本文介绍了如何更改symfony 2 doctrine mapper以使用我的自定义目录,而不是我的实体目录下的bundle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的symfony 2.3应用程序中使用doctrine作为我的持久层。我想使用像 /MyBundleName/User/User.php 而不是 /MyBundleName/Entity/User.php 。在这个意义上,我发现这是有价值的,我不喜欢在同一个目录中拥有不同类型的多个实体的想法。即( /MyBundleName/Entity/User.php &< code> /MyBundleName/Entity/Product.php )。我觉得这是凌乱的。我更喜欢这个,而不是( /MyBundleName/User/User.php &< code> /MyBundleName/Product/Product.php

有没有,我可以直接将doctrine ORM直接映射到使用显式目录,而不是默认到我的Bundle的Entity Directory ?



我想将所有相关文件保存在相应的目录中,例如 ProductProvider /MyBundleName/Product/ProductProvider.php 任何帮助将不胜感激。

解决方案

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

  doctrine:
orm:
default_entity_manager:默认
auto_generate_proxy_classes:%kernel.debug%

entity_managers:

默认:
connection:default
映射:

test01:
连接:test01
映射:
产品:
类型:yml
dir:%kernel.root_dir% /../src/Cerad/Bundle/Test01Bundle/Product
前缀:Cerad\Bundle\Test01Bundle\Product
别名:Product
is_bundle:false
user:
类型:yml
dir:%kernel.root_dir%/ .. / src / Cerad / Bundle / Test01Bundle / User
前缀:Cerad\Bundle\Test01Bundle\User
别名:用户
is_bundle:false

不用担心is_bundle:false条目。实体仍然可以生活在一起。教义不在乎如果您想知道,alias参数可以让您执行以下操作:

  $ repo = $ em-> getRepository 产品:产品); 


I want to use doctrine as my persistence layer in my symfony 2.3 application. I want to use a folder structure like /MyBundleName/User/User.php instead of /MyBundleName/Entity/User.php. I find this valuable in the sense that I don't like the idea of having multiple entities of different types in the same directory. i.e. ( /MyBundleName/Entity/User.php && /MyBundleName/Entity/Product.php ). I feel like this is messy. I would prefer this instead i.e ( /MyBundleName/User/User.php && /MyBundleName/Product/Product.php ).

Is there anyway that I can explicitly map doctrine ORM directly to the use an explicit directory instead of defaulting to the Entity Directory of my Bundle?

I would like to keep all related files in there respective directory such as ProductProvider in the the /MyBundleName/Product/ProductProvider.php Any help would be greatly appreciated.

解决方案

Just to follow up a bit on @Imanol's correct answer, it is possible to have your entities in multiple directories under one entity manager:

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

Don't worry about the is_bundle: false entries. The entities can still live in a bundle. Doctrine does not care. And in case you are wondering, the alias parameter lets you do things like:

$repo = $em->getRepository("Product:Product");

这篇关于如何更改symfony 2 doctrine mapper以使用我的自定义目录,而不是我的实体目录下的bundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆