Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the entities namespaces and alias in Doctrine2?

In the documentation I saw this method:

addEntityNamespace($alias, $namespace);

But I can't find anywhere what is it about.

Any ideas?

like image 693
ÉricP Avatar asked Feb 24 '23 21:02

ÉricP


1 Answers

Entity namespaces are a shortcut to aliasing Entities when pointing to other classes. A good example of an entity namespace is inside DQL queries.

When you define a namespace, like: ->addEntityNamespace('app', 'Application\Entity'); You can then refer to them easily. In a DQL sample, instead of write this:

SELECT u FROM Application\Entity\User u

You can do that:

SELECT u FROM app:User u

I hope this helps. =)

Cheers,

like image 53
Guilherme Blanco Avatar answered Mar 07 '23 05:03

Guilherme Blanco