我在實體類此功能,但getDoctrine不喜歡......如何在實體內使用entityManager?
public function getObject()
{
$em = $this->getDoctrine()->getEntityManager();
switch($this->objectType)
{
case 'video':
return $em->getRepository('fdj2012AdminBundle:Video')->find($this->objectId);
break;
case 'default':
return false;
break;
}
}
如何使用EntityManager我的實體裏面?
[在Doctrine 2.0實體中使用EntityManager]的可能重複(http://stackoverflow.com/questions/4108291/using-entitymanager-inside-doctrine-2-0-entities)。您的實體不應該瞭解實體管理器,而應該在需要時將所需的任何數據/服務傳遞給您的實體。 – richsage
我從樹枝模板得到這個......但是我會加深這一點。謝謝 –
你需要表繼承嗎? - > http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html – toine