开发者

Limit amount of records retrieved when using Doctrine DQL in Symfony2

I have the following query:

   $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'
            );

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:

Error: Expected end of string, got 'LIMIT'.

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

What am I doing wrong?


There is no statement like LIMIT for DQL currently, as far as I know.

You have to use Query::setMaxResults().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜