Doctrine2 Entity Namespace

annotations, configuration, doctrine-orm, entity, namespaces

Solution

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.

Problem

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"?

Original source