如何配置Doctrine以在Symfony 4上使用yaml映射

时间:2017-12-21 08:04:24

标签: symfony doctrine-orm mapping yaml symfony4

我是Symfony 4

的新手

我使用Doctrine,我想使用 yaml 实体映射。 所以我配置了文件doctrine.yaml并将type:annotation更改为type:yml

当我尝试php bin/console make:entity时,没有生成链接到此实体的yaml映射文件

这是我的doctrine.yaml文件:

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_URL): ''

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4

        # With Symfony 3.3, remove the `resolve:` prefix
        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: yml
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

1 个答案:

答案 0 :(得分:5)

根据您的需求进行映射的示例:

更改文件名,包括" orm "文字doctrine.orm.yaml,并查看以下示例中的dir选项(符合您的需求):

App:
    is_bundle: false
    type: yml
    # "dir" in this case must be pointed where are stored your doctrine files (can be anywhere inside the project dir)
    dir: "%kernel.project_dir%/config/doctrine"
    prefix: App\Entity

参考:Doctrine yaml mapping (v2.6 current)