原则:FetchAll()有限制 [英] Doctrine :FetchAll() with limits

查看:96
本文介绍了原则:FetchAll()有限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个fetchAll()有限制?您是否知道symfony2的实体经理是否有可能?



我目前的代码(全部获取,无限制):

  $ repository = $ this-> getDoctrine() - > getRepository('MyBundle:Download'); 
$ product = $ repository-> findAll();

感谢大家。
最好的问候,



编辑:

  $ em = $ this-> getDoctrine() - > getRepository('MyBundle:Download'); 
$ ouput = $ em-> findBy(array(),array('id'=>'DESC'),5);

返回最后5行。



感谢所有。

解决方案

通常有助于检查来源代码

  Doctrine\ORM\EntityRepository 

public function findAll()
{
return $ this-> findBy(array());
}
public function findBy(array $ criteria,array $ orderBy = null,$ limit = null,$ offset = null)
{
$ persister = $ this-> _em-> getUnitOfWork() - > getEntityPersister($这 - > _entityName);

返回$ persister-> loadAll($ criteria,$ orderBy,$ limit,$ offset);
}


I want to make a fetchAll() with limit ? Do you know if it's possible with the entity manager of symfony2 ?

My current code (Fetch all, without limit):

$repository = $this->getDoctrine()->getRepository('MyBundle:Download');
$product    = $repository->findAll();

Thanks you all. Best regards,

EDIT:

$em = $this->getDoctrine()->getRepository('MyBundle:Download');
$ouput = $em->findBy(array(), array('id' => 'DESC'),5);

Return the 5 last rows.

Thanks all.

解决方案

It's often instructive to check the source code.

Doctrine\ORM\EntityRepository 

public function findAll()
{
    return $this->findBy(array());
}
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
{
    $persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName);

    return $persister->loadAll($criteria, $orderBy, $limit, $offset);
}

这篇关于原则:FetchAll()有限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆