Generate your own repository, then create a method in it that contains the DQL.
In your entity definition (if you're using annotations): /* * @orm\Table(name="thing") * @orm\Entity(repositoryClass="Me\MyBundle\Repositories\ThingRepository") */ Then re-run app/console doctrine:generate:entities MeMyBundle to create the repository class for you. findAll() will still work, but you can now add a method like this: public function getThings($limit = 5, $offset = 0) { $q = $this->_em->createQuery('SELECT t FROM MeMyBundle:Thing t ORDER BY t.created_at DESC'); $q->setFirstResult( $offset ); $q->setMaxResults( $limit ); return $q->getResult(); } And then call it from your controller like this: $things = $this->get('doctrine') ->getEntityManager() ->getRepository('MeMyBundle:Thing') ->getThings(5,0); On 8 Jun 2011, at 08:54, Thomas wrote: > Hi all, > > I didn't found in the doctrine documentation how to limit my results when i'm > fetching all my news. > > I want to limit my results with only 5 news (like in SQL LIMIT 0,5). > > I've done this : > > $news = new News(); > $news = $this->get('doctrine') > ->getEntityManager() > ->getRepository('CompanySiteBundle:News') > ->findAll(); > > It's work fine but i have all my news, and i don't really want to have SQL > order in my Controller.. -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en