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"?
The EntityManager is the central access point to ORM functionality. It can be used to find, persist, flush and remove entities.
A Doctrine proxy is just a wrapper that extends an entity class to provide Lazy Loading for it. By default, when you ask the Entity Manager for an entity that is associated with another entity, the associated entity won't be loaded from the database, but wrapped into a proxy object.
Doctrine uses the Identity Map pattern to track objects. Whenever you fetch an object from the database, Doctrine will keep a reference to this object inside its UnitOfWork. The array holding all the entity references is two-levels deep and has the keys root entity name and id.
The Doctrine Project is the home to several PHP libraries primarily focused on database storage and object mapping. The core projects are the Object Relational Mapper (ORM) and the Database Abstraction Layer (DBAL) it is built upon.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With