Doctrine 2 ORM使用可恶的CamelCase创建类 [英] Doctrine 2 ORM creates classes with hateful CamelCase

查看:122
本文介绍了Doctrine 2 ORM使用可恶的CamelCase创建类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Doctrine创建了yaml配置。当我尝试使用教义orm:generate-entities 时,它会使用驼峰式的getter和setter方法创建php文件。因此, is_public 字段将转换为 setIsPublic getIsPublic 方法。太好了如何获得 set_is_public get_is_public ?我可以手动编辑生成的php文件,但是我不知道更改架构会发生什么。

I created yaml configuration for Doctrine. When I'm trying doctrine orm:generate-entities, it creates php files with getters and setters in camel case. So, is_public field transforms into setIsPublic and getIsPublic methods. It's owful. How can I get set_is_public and get_is_public? I can manually edit generated php files, but I don't know what will happen when I change the schema.

推荐答案

您可以选择命名策略,Doctrine将使用该策略使用以下项来生成商品:

You can choose a naming strategy that Doctrine will use to generate the items using:


使用命名策略,您可以提供规则,以便在未给出
表/列名称的情况下自动
生成数据库标识符,列和表名。此功能有助于减少映射文档的
详细程度,消除重复噪声(例如:
TABLE _)。

Using a naming strategy you can provide rules for automatically generating database identifiers, columns and tables names when the table/column name is not given. This feature helps reduce the verbosity of the mapping document, eliminating repetitive noise (eg: TABLE_).

对于您的特定情况,我认为您正在寻找类似的东西:

For your specific case, I think you're looking at something like:

$namingStrategy = new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(CASE_LOWER);
$configuration()->setNamingStrategy($namingStrategy);

链接的主题继续向您展示如何编写自己的自定义命名策略。

The linked topic goes on to show you how you can write your own custom naming strategy.

如果您使用的是Symfony,则为更容易(就像大多数事情都在Symfony中一样,但这只是我的看法),通过 config.yml

If you're using Symfony, it's even easier (like most things are with Symfony, but that's just my opinion) via config.yml:

doctrine:
    orm:
        naming_strategy: doctrine.orm.naming_strategy.underscore

这篇关于Doctrine 2 ORM使用可恶的CamelCase创建类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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