Program Club

Symfony2에서 ObjectManager와 EntityManager의 차이점은 무엇입니까?

proclub 2020. 11. 24. 20:25
반응형

Symfony2에서 ObjectManager와 EntityManager의 차이점은 무엇입니까?


사용자 지정 양식 유형에서 사용할 때 Doctrine\Common\Persistence\ObjectManagerDoctrine\ORM\EntityManager사용하는 경우 의 차이점은 무엇입니까 ?

$this->em->getRepository()을 모두 사용하여 저장소를 가져올 수 있습니다 $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;
    }

 }

대신에:

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;
    }

 }

ObjectManager인터페이스이며 EntityManagerORM 구현입니다. 이것이 유일한 구현은 아닙니다. 예를 들어 DocumentManagerMongoDB에서 ODM도이를 구현합니다. ObjectManager모든 구현의 공통 하위 집합 만 제공합니다.

양식 유형이 모든 ObjectManager구현에서 작동 하도록하려면이를 사용하십시오. 이렇게하면 ORM에서 ODM으로 전환 할 수 있으며 유형은 여전히 ​​동일하게 작동합니다. 그러나 EntityManagerODM으로 전환 할 계획이없고 제공 만하는 특정 항목이 필요 하면 대신 사용하십시오.

참고 URL : https://stackoverflow.com/questions/10285783/difference-between-objectmanager-and-entitymanager-in-symfony2

반응형