Symfony2 中使用 YAML 的教义映射 [英] Doctrine Mapping in Symfony2 using YAML

查看:27
本文介绍了Symfony2 中使用 YAML 的教义映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 Symfony2 中 Doctrine 的 YAML 配置的问题.

I have a question regarding YAML configuration of Doctrine in Symfony2.

我通过doctrine:generate:entity"创建了一个实体,并选择 YAML 作为映射格式.这没有在 ../Entity/"MyEntity".php 上添加任何元数据,这将允许我更新或创建我的架构.

I have created an entity via "doctrine:generate:entity", and chose YAML as the mapping format. This didn't add any metadata on ../Entity/"MyEntity".php, which would allow me to update or create my schema.

例如,如果我运行

./app/console doctrine:schema:create

它失败了,说:

[RuntimeException]                                                 
Bundle "MySuperBundle" does not contain any mapped entities.

我的自动映射已设置为true".

My automapping is already set to "true".

如果我选择使用注释配置,这不会有问题.

If I choose to use annotation config this would not be a problem.

我错过了什么吗?我应该采取什么额外的步骤吗?

Did I miss something? Are there any extra steps that I should take?

提前谢谢你,问候,

伊万

推荐答案

我刚刚在看 Doctrine 配置初始化代码时玩得很开心.我发现的是:

I just had a fun time looking at the Doctrine config initialisation code. What I found was:

  • 使用 auto_mapping 会导致为单个默认实体管理器设置各种默认值;它将 type 值保留为 false
  • 如果 type 为 false,则配置代码会在默认目录中查找可能的配置文件,并且一旦找到具有有效扩展名的文件,它就会决定这是完成配置的方式,按顺序 xmlymlphp
  • 如果它没有找到任何它假定 annotation
  • Using auto_mapping results in various defaults being set for the single default entity manager; it leaves the type value as false
  • If type is false the config code looks into the default directory for likely config files, and as soon as it finds a file of a valid extension it decides that that's the way config is being done, in the order xml, yml, php
  • If it doesn't find any of those it assumes annotation

Bundle/Resources/config/doctrine 文件夹中还有其他内容吗?如果是这样,它可能会抛出自动检测.

Do you have anything else at all in the Bundle/Resources/config/doctrine folder? If so, it might be throwing off the auto-detection.

除此之外,基本上,如果您使用了默认值,并且有一些实体类和有效配置,那么您所做的应该可以在没有任何额外配置的情况下工作.你说auto_mapping"是真的,但是你有没有改变任何其他的 Doctrine 配置?

That aside, basically if you've used defaults, and have some entity classes and valid config, what you're doing should be working without any additional config. You've said "auto_mapping" is true, but have you changed any other bit of Doctrine config?

尝试显式配置内容可能是一个想法,例如如 Symfony Doctrine docs 中所述,从默认配置开始

It might be an idea to try configuring stuff explicitly, e.g. as described in the Symfony Doctrine docs, go from default config

doctrine:
    dbal:
        driver:   "%database_driver%"
        #etc

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

显式

doctrine:
    dbal:
        driver:   "%database_driver%"
        #etc

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: false
        mappings:
            MySuperBundleName:
                type: yml
                dir: Resources/config/doctrine

这篇关于Symfony2 中使用 YAML 的教义映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆