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

在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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀