doutou19761022 2014-05-01 08:34
浏览 43
已采纳

在symfony2中设置orm配置与Sylius类似

I'm having a tough time setting up doctrine ORM configuration using Symfony2. I'm setting up the ORM files using yml.

I've looked at a couple of open source Symfony2 projects(mostly Sylius) and the norm seems to be placing Entities outsides of the bundles in a folder called Components but placing the ORM definitions in the bundles. Can anyone suggest any useful resources to help me set this up? The default seems to require my entities to be within bundles which I don't want to do because some of my entities have scope across multiple bundles.

I've noticed in the documentation you can configure entity managers individually but I can't see how the configuration options below can achieve what I'm after, especially because the entities may not all share the same prefix:

mappings:
    AcmeOrderBundle:
        type:              ~
        dir:               ~
        alias:             ~
        prefix:            ~
        is_bundle:         ~

Any help with this would be greatly appreciated and I can provide more information if necessary.

  • 写回答

1条回答 默认 最新

  • douchujian8124 2014-05-01 12:33
    关注

    Here is an example using a couple of the options:

        entity_managers:
    
            games:
               connection: games
               mappings:
                    CeradGameBundle: 
                        type:   yml
                        dir:    Resources/config/doctrine2
                        prefix: Cerad\Bundle\GameBundle\Doctrine\Entity
    

    The dir points to where the orm.yml files live. As shown it is relative to the bundle. But you can replace it with an absolute path if you want.

    The prefix is basically the namespace of your entities.

    As far as multiple prefixes go, you can have multiple mappings for a given manager. Make one mapping per prefix.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?