Symfony 学说 auto_mapping 无法识别

2022-01-03 00:00:00 php symfony doctrine sonata doctrine-orm

我添加了 SonataUserBundle,但出现错误

I have added SonataUserBundle and it is giving error

config.yml

doctrine: 
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

        entity_managers:
            default:
                mappings:
                    ApplicationSonataUserBundle: ~
                    SonataUserBundle: ~

错误

无法识别的选项naming_strategy、auto_mapping、dql"下"doctrine.orm"

Unrecognized options "naming_strategy, auto_mapping, dql" under "doctrine.orm"

推荐答案

您正在混合缩短配置和完整配置.

You are mixing shortened and full configuration.

如果您只想使用默认实体管理器,那么您可以将所有内容放在 orm 键下(缩短的配置).这将被重新映射,以便它在包扩展的 doctrine.orm.entity_managers.default 下.

If you just want to use the default entity manager then you can place everything under the orm key (the shortened config). This will be remapped so that it is under doctrine.orm.entity_managers.default by the bundle extension.

但是,如果您想更改实体管理器的名称或使用多个名称,则需要使用指定每个实体管理器的完整配置.

If, however, you want to chaneg the name of the entity manager or use multiples then you would need to use the full configuration specifying each entity manager.

缩短配置

doctrine: 
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            ApplicationSonataUserBundle: ~
            SonataUserBundle: ~

完整配置

doctrine: 
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        entity_managers:
            default:
                naming_strategy: doctrine.orm.naming_strategy.underscore
                auto_mapping: true
                mappings:
                    ApplicationSonataUserBundle: ~
                    SonataUserBundle: ~

相关文章