i am trying to limit rows which return from doctrine's FindAll method.
public function getActiveUsersByPoint($limit = 100){
$users = $this->userRepository->findAll();
return $users;
}
This code work but i can't use $limit variable for limitting results. How can i done this ?
The EntityRepository#findBy() method additionally accepts orderings, limit and offset as second to fourth parameters:
$tenUsers = $em->getRepository('MyProject\Domain\User')
->findBy(
array('age' => 20), // $where
array('name' => 'ASC'), // $orderBy
10, // $limit
0 // $offset
);
In order to find all results, you should pass an empty array to the findBy method, I think it is what you pretend:
$users= $em->userRepository->findBy(
array(),
array('id' => 'DESC'),
10,
0
);
First param is an empty array, which it is equivalent to findAll(), then the order (I put id as sample), then the limit and finally the offset.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With