Difference between ObjectManager and EntityManager in Symfony2?

What is the difference between Doctrine\Common\Persistence\ObjectManager and Doctrine\ORM\EntityManager when used in a custom type of form?

I can get the repository using both $this->em->getRepository() and $this->om->getRepository() .

 class MyFormType extends \Symfony\Component\Form\AbstractType { /** * @var Doctrine\ORM\EntityManager */ protected $em; public function __construct(Doctrine\ORM\EntityManager $em) { $this->em = $em; } } 

Instead:

 class MyFormType extends \Symfony\Component\Form\AbstractType { /** * @var Doctrine\Common\Persistence\ObjectManager */ protected $om; public function __construct(Doctrine\Common\Persistence\ObjectManager $om) { $this->om = $om; } } 
+50
symfony doctrine doctrine2 symfony-forms
Apr 23 '12 at 18:01
source share
1 answer

ObjectManager is an interface, and EntityManager is its implementation of ORM. This is not the only implementation; for example, DocumentManager from MongoDB ODM implements it. ObjectManager provides only a common subset of all its implementations.

If you want your form type to work with any ObjectManager implementation, use it. This way you can switch from ORM to ODM, and your type will work the same. But if you need something specific that only EntityManager provides and does not plan to switch to ODM, use it instead.

+86
Apr 23 '12 at 18:13
source share
— -



All Articles