這是我custome查詢:Symfony2 - 如何根據自定義查詢獲取實體對象?
$query = $em->createQuery("SELECT max(d.id) FROM MyBundle:DBTableEntity d ");
$max_incoming_id = $query->execute();
我希望它返回的實體對象,就像下面這樣:
$EntityObj = $resource->getRepository("MyBundle:DBTableEntity")->findAll();
任何想法如何做到這一點?
解決方案: $查詢= $資源 - > createQuery(「SELECT d FROM MyBundle:MyEntity d where d.id> 5); $ entities = $ query-> execute(); foreach($ entities = $ i => $ entity): //獲取實體ID $ entity-> getId(); endforeach; 就是這樣! – Edge