2011-08-30 67 views
18

有誰知道是否有一種快速的方法可以使用Doctrine無需使用DQL來獲取表中的所有記錄。Doctrine 2 - 獲取所有記錄

我錯過了什麼,或者你是否需要在課堂上寫公共職能?

回答

40

如果你有一個實體類(Doctrine Repository manual):

$records = $em->getRepository("Entities\YourTargetEntity")->findAll(); 

如果你沒有實體類(PDO manual):

$pdo = $em->getCurrentConnection()->getDbh(); 
$result = $pdo->query("select * from table"); //plain sql query here, it's just PDO 
$records = $pdo->fetchAll(); 
+1

完美的感謝。工作。我也發現這有幫助:http://symfony.com/doc/2.0/book/doctrine.html –