How do I change symfony 2 doctrine mapper to use my custom directory instead of my Entity Directory under the bundle

后端 未结 3 500
甜味超标
甜味超标 2021-01-05 02:29

I use doctrine in my symfony 2.3 application. I want to use a folder structure like

/MyBundleName/User/User.php

for my Entities.

3条回答
  •  孤街浪徒
    2021-01-05 03:09

    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");
    

提交回复
热议问题