[英]Symfony2 change doctrine generated mapping and entity location
在我的Symfony2項目中,我有一個名為MyBundle \\ BlogBundle的軟件包。 我正在使用命令:
php app/console doctrine:mapping:import MyBundleBlogBundle xml
以xml格式生成映射文件。 生成映射文件的默認位置是:
src/MyBundle/BlogBundle/Resources/config/doctrine
我想改變這一點。 如果該目錄可能是:
src/MyBundle/BlogBundle/Mapping
這甚至可能嗎? 最重要的是,我想將我的Entity目錄更改為:
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。 但我還不了解很多。
我可以獲得doctrine:mapping:import命令來處理我想要的目錄嗎? 或者我是否需要忘記此命令並自己創建所有映射和實體?
我寧願用編譯器通行證來解決它,但不知道如何解決。 最重要的是使用Model目錄而不是Entity目錄。
這是一個有效的例子。 在我的例子中,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文件的最終位置。 您必須自己復制它們,然后編輯實體路徑。 這是一次性的交易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.