Doctrine:带有限制的FetchAll()

Dim*_*tri 13 entitymanager symfony doctrine-orm

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

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

$repository = $this->getDoctrine()->getRepository('MyBundle:Download');
$product    = $repository->findAll();
Run Code Online (Sandbox Code Playgroud)

谢谢大家.最好的祝福,

编辑:

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

返回最后5行.

谢谢大家.

Cer*_*rad 54

检查源代码通常很有启发性.

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);
}
Run Code Online (Sandbox Code Playgroud)

  • +1不是直接给出解决方案,而是将OP指向他可以找到的地方a)实际答案和b)更广泛地理解他的问题的背景 (5认同)