2011-08-30 107 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 –