本文介绍了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:

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

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创建类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 07:06
查看更多