duanfu1945 2015-02-23 19:37
浏览 54

Symfony2更改了doctrine生成的映射和实体位置

In my Symfony2 project I have one bundle called MyBundle\BlogBundle. I'm using the command:

php app/console doctrine:mapping:import MyBundleBlogBundle xml

To generate mapping files in xml format. The default location in which the mapping files are generated is:

src/MyBundle/BlogBundle/Resources/config/doctrine

I would like to change that. It would be very nice if that directory could be:

src/MyBundle/BlogBundle/Mapping

Is this even possible to do? Above all I would like to change my Entity directory to:

src/MyBundle/BlogBundle/Model

This also does not seems to work with the doctrine:mapping:import command. For this to change I tried stuff like changing the config.yml to:

    orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    entity_managers:
        MyBundle:
            mappings:
                MyBundleBlogBundle:
                    mapping: true
                    type: xml
                    dir: Model
                    alias: 'MyBundleBlogBundle'
                    prefix: 'MyBundle\BlogBundle\Model'
                    is_bundle: true

But this also does not seems to work. After this I did some research on Compiler Passes as used by e.g. the FosUserBundle. But I don't understand a lot of that yet.

Can I get the doctrine:mapping:import command to work with my desired directories? Or do I need to forget this command and create all the mappings and entities myself?

I would prefer to solve it with a Compiler Pass, but do not know how. Most important is the use of the Model directory instead of the Entity dir.

  • 写回答

1条回答 默认 最新

  • dongpan3001 2015-02-23 20:19
    关注

    Here is a working example. In my case, is_bundle is set to false but it should work pretty much the same. As @user3749178 has suggested, your dir is probably wrong. Tweak the locations as necessary.

    doctrine:
    entity_managers:
    
      games:
        connection: games
        mappings:
          foo1: 
            prefix: Cerad\Bundle\ProjectGameBundle\Doctrine\Entity\Foo1
            type:   yml
            dir:    "%kernel.root_dir%/../src/ProjectGameBundle/Doctrine/EntityMapping/Foo1"
            is_bundle: false
          foo2: 
            prefix: Cerad\Bundle\ProjectGameBundle\Doctrine\Entity\Foo2
            type:   yml
            dir:    "%kernel.root_dir%/../src/ProjectGameBundle/Doctrine/EntityMapping/Foo2"
            is_bundle: false
    

    Update

    Looks like I misunderstood the main point of the question. Take a look at:

    vendor/doctrine/doctrine-bundle/
    
    namespace Doctrine\Bundle\DoctrineBundle\Command
    
    class ImportMappingDoctrineCommand extends DoctrineCommand
    {
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $bundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
    
        $destPath = $bundle->getPath();
        $type = $input->getArgument('mapping-type') ? $input->getArgument('mapping-type') : 'xml';
        if ('annotation' === $type) {
            $destPath .= '/Entity';
        } else {
            $destPath .= '/Resources/config/doctrine';
        }
    

    As you can see, the mapping file directory is hard coded. No way to adjust where the xml files will end up. You will have to copy them over yourself and then edit the entity path. It's a one shot deal.

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计