2015-02-23 36 views
0

在我的Symfony2項目中,我有一個名爲MyBundle \ BlogBu​​ndle的包。我正在使用以下命令:Symfony2更改原則生成的映射和實體位置

php app/console doctrine:mapping:import MyBundleBlogBundle xml 

以xml格式生成映射文件。映射文件生成的默認位置是:

src/MyBundle/BlogBundle/Resources/config/doctrine 

我想改變這一點。這將是非常好的,如果該目錄可能是:

src/MyBundle/BlogBundle/Mapping 

這甚至可能嗎?最重要的是,我想將我的實體目錄更改爲:

src/MyBundle/BlogBundle/Model 

這也似乎不適用於doctrine:mapping:import命令。爲了改變這種情況,我嘗試了將config.yml更改爲:

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 

但是這似乎也不起作用。在此之後,我做了一些關於編譯器通行證的研究。 FosUserBundle。但我還沒有很明白這一點。

我可以得到教條:mapping:import命令來處理我想要的目錄嗎?還是我需要忘記這個命令並自己創建所有的映射和​​實體?

我寧願用Compiler Pass解決它,但不知道如何。最重要的是使用Model目錄而不是Entity目錄。

+0

在config中更改'dir'並將文件從'/ Resources/config/doctrine'手動移動到'/ Model'後,一切工作正常嗎? – 2015-02-23 20:17:01

+0

問題是xml文件中的實體位置仍然指向實體目錄而不是配置的(模型)目錄。 – Faiawuks 2015-02-23 20:33:20

+0

最後決定使用默認的Symfony2目錄結構。 – Faiawuks 2015-03-13 08:21:46

回答

0

這是一個工作示例。在我的情況下,is_bundle設置爲false,但它應該幾乎相同。正如@ user3749178所建議的,您的目錄可能是錯誤的。根據需要調整位置。

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 

更新

貌似我誤解了這個問題的要點。看看:

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'; 
    } 

正如你所看到的,映射文件目錄是硬編碼的。沒有辦法調整xml文件的最終位置。您必須將它們複製到自己,然後編輯實體路徑。這是一筆一筆交易。

+0

當然,這工作,但我怎麼能得到的教條:映射:導入命令指向正確的目錄MyBundle \ BlogBu​​ndle \ Model \而不是MyBundle \ BlogBu​​ndle \實體 – Faiawuks 2015-02-23 21:34:24

+0

看到我的更新。你必須編寫自己的命令來更改文件夾。 – Cerad 2015-02-24 20:36:03