I want to know if it is possible to query only a specific amount of objects and order them. For example I want to query for the newest products added, and I want to get only the newest 10 products from the table.
I dont know if you can order a specific amount in the controller, but I know that you can do slice
in the twig. However getting the right amount straight from the query would be much more sufficient if possible.
However for some reason I cant even sort the product that I get(http://symfony.com/doc/current/book/doctrine.html#fetching-objects-from-the-database). The documentation clearly shows that you can easily order objects. However with my code it does not order:
$newProducts = $em->getRepository('MpShopBundle:Product')->findBy(array(), array('id' => 'DESC'));
This returns all of the products. How to query for only 10 of all of them?
How can I achieve what I want?