If I use the findBy method of the repository class, how can I limit the size of the result set?
In the Doctrine 2.1 method, EntityRepository # findBy () now accepts additional parameters for ordering, constraint, and offset.
see the full list of new features in doctrine 2.1 (404) Related link to findBy and findOneBy
Example:
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
using:
$product = $repository->findBy( array('name' => 'foo'), array('price' => 'ASC'), $myLimit, $myOffset );
For the Doctrine Query Language you have:
QueryBuilder::setMaxResults(integer $maxResults)
The findBy () method of the shared repository class does not support this.
I would write my own repository (as described here ) and override findBy () to take extra parameters. Your new implementation may use query builder or simple-DQL to create the correct query. (I would use querybuilder, since you can probably just pass the $ critera parameter directly to QueryBuilder :: where () )