有没有办法修改配置文件外面的doctrine的实体映射配置? [英] Is there a way to modify the entity mapping configuration for doctrine outside the config file?

查看:157
本文介绍了有没有办法修改配置文件外面的doctrine的实体映射配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的标准Symfony2应用程序中,我有一些绑定与一些实体。这些实体中的一些不位于标准文件夹中,因为doctrine的自动发现(例如 / src / Acme / DemoBundle / Entities ),但位于不同的位置。 >

我可以轻松地使用 config.yml 来告诉学说使用不同的位置,如下所示:

  doctrine:
orm:
auto_mapping:false
映射:
AcmeDemoBundle:
type:注释
前缀:Acme\DemoBundle\Entities\
dir:%kernel.cache_dir%\Acme\DemoBundle\Entities

这个工作。但是说,我有10个捆绑包,不同的映射, config.yml 变得非常快。有另一种方法,例如使用CompilerPass或通过DependencyInjection,所以我不需要在我的 config.yml 中添加所有实体?我已经看过 DoctrineBundle ,但迄今没有运气。

解决方案

p>要回答自己:



最简单的方法是调整自动加载,没有必要修改设置。在Symfony的autoload.php的标准分发中,您必须向registerNamespace-method添加另一个位置:

  $ loader-> registerNamespaces (数组(
[...]
'Foo'=>数组(__ DIR __。'/ .. / src / dirA',__DIR __。'/ .. / src / dirB')
));

原则将在dirA中首先在Foo命名空间中查找实体,然后在dirB中查找实体发现。


In my standard Symfony2-app I'm having a bunch of bundles with some entities. Some of these entities are not located in the standard folder the automapping of doctrine finds out (e.g. /src/Acme/DemoBundle/Entities) but in a different location.

I could easily use config.yml to tell doctrine to use a different location like this:

doctrine:
    orm:
        auto_mapping: false
        mappings:
           AcmeDemoBundle:
              type: annotation
              prefix: Acme\DemoBundle\Entities\
              dir: %kernel.cache_dir%\Acme\DemoBundle\Entities

This works. But say I'm having 10 bundles with a different mapping the config.yml gets bloated very fast. Is there another way, e.g. with a CompilerPass or via DependencyInjection, so I don't need to add all entities in my config.yml? I already looked into the DoctrineBundle, but had no luck so far.

解决方案

To answer myself:

the most simple way is to adjust the autoloading, there is no need to modify the settings. In Symfony's standard distribution in autoload.php you have to add another location to the registerNamespace-method:

$loader->registerNamespaces(array(
    [...]
    'Foo' => array(__DIR__.'/../src/dirA', __DIR__.'/../src/dirB')
));

Doctrine will then look for entities in the "Foo" namespace first in dirA and then in dirB if not found.

这篇关于有没有办法修改配置文件外面的doctrine的实体映射配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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