Doctrine2实体命名空间 [英] Doctrine2 Entity Namespace

查看:195
本文介绍了Doctrine2实体命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来Doctrine2并想知道我怎么能告诉学说我的命名空间的实体使用。
我现在的配置<一href=\"http://docs.doctrine-project.org/en/latest/reference/configuration.html#obtaining-an-entitymanager\"相对=nofollow>是这样的。

i'm new to Doctrine2 and like to know how i can tell Doctrine which namespace my entities use. My current configuration is this.

我所有的实体都在命名空间项目\\实体。
所以,每次我想获得实体颜色,我必须写:

All my entities are in namespace "project\entity". So, everytime i want to obtain the entity "Color", i have to write:

$em->getRepository("project\\entity\\Color")

如何配置主义总是使用命名空间项目\\实体?

How can i configure Doctrine to always use namespace "project\entity"?

推荐答案

您可以使用您的配置对象上addEntityNamespace创建一个命名空间别名来接近你想要什么:

You can come close to what you want by using addEntityNamespace on your config object to create a namespace alias:

$em->getConfiguration()->addEntityNamespace('NS1', 'Project\Entity');

$colorRepo = $em->getRepository('NS1:Color');

有关查询工作为好。

顺便说一句,\\\\ \\\\实体颜色项目项目\\实体\\颜色。我也建议资本项目和实体只是为了符合标准。

By the way, "project\\entity\\Color" can also be written as 'project\entity\Color'. I would also suggest capitalizing Project and Entity just to conform to standards.

这篇关于Doctrine2实体命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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