반응형
Symfony2에서 ObjectManager와 EntityManager의 차이점은 무엇입니까?
사용자 지정 양식 유형에서 사용할 때 Doctrine\Common\Persistence\ObjectManager와 Doctrine\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으로 전환 할 계획이없고 제공 만하는 특정 항목이 필요 하면 대신 사용하십시오.
반응형
'Program Club' 카테고리의 다른 글
| re.sub 교체 패턴에서 그룹 캡처에 대한 역 참조 처리 (0) | 2020.11.24 |
|---|---|
| git-빈 폴더를 제거하고 변경 사항을 푸시하는 방법은 무엇입니까? (0) | 2020.11.24 |
| ConcurrentDictionary.TryAdd가 실패 할 수 있습니까? (0) | 2020.11.24 |
| NewtonSoft.Json 유형 IEnumerable의 속성을 사용하여 클래스 직렬화 및 역 직렬화 (0) | 2020.11.24 |
| 두 구문의 의미 적 유사성을 알려주는 알고리즘이 있습니까? (0) | 2020.11.24 |