Doctrine2实体命名空间 [英] Doctrine2 Entity Namespace
问题描述
我是Doctrine2的新手,并且想知道我可以如何告诉Doctrine我的实体使用哪个命名空间。
我的当前配置是这。 p>
我的所有实体都在命名空间project\entity中。
所以,每次我想获得实体颜色,我必须写:
$ em- ; getRepository(project\\\entity\\Color)
doctrine总是使用命名空间project\entity?
你可以通过使用addEntityNamespace config对象以创建命名空间别名:
$ em-> getConfiguration() - > addEntityNamespace('NS1' Project\Entity');
$ colorRepo = $ em-> getRepository('NS1:Color');
适用于查询。
顺便说一句,project\\entity\\Color
也可以写成'project\entity\Color'
。我还建议资本化项目和实体只是为了符合标准。
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"?
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');
Works for queries as well.
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屋!