在Symfony2中使用Doctrine DQL时限制检索的记录数量 [英] Limit amount of records retrieved when using Doctrine DQL in Symfony2
本文介绍了在Symfony2中使用Doctrine DQL时限制检索的记录数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下查询:
$latestcontent = $em->createQuery('
SELECT c.title, c.content, c.lastedit, a.firstname, a.surname
FROM ShoutMainBundle:Content c, ShoutMainBundle:Admin a
WHERE c.author = a.id
ORDER BY c.lastedit ASC'
);
我需要做的是限制从此查询返回的记录数量。但是,当我向SQL查询添加LIMIT 10时,它会返回此错误:
What I need to do, is limit the amount of records returned from this query. However, when I add LIMIT 10 to the SQL query, it returns this error:
错误:预期的字符串结束,得到'LIMIT'
Error: Expected end of string, got 'LIMIT'.
所以,我看了一下,发现你可以添加 - > limit(10)
到代码(查询后)。但是这会引发这个PHP错误:
So, I had a look and found that you could do add ->limit(10)
to the code (after the query). But this then throws up this PHP error:
Fatal error: Call to undefined method Doctrine\ORM\Query::limit() in C:\wamp\www\src\Shout\AdminBundle\Controller\DefaultController.php on line 22
我做错了什么?
推荐答案
目前没有关于DQL的LIMIT的声明,据我所知。
There is no statement like LIMIT for DQL currently, as far as I know.
你必须使用 Query :: setMaxResults()。
这篇关于在Symfony2中使用Doctrine DQL时限制检索的记录数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文