sort table records in descending order - symfony

I have a table of records in the db where the last inserted record is the last in the table row of records. In my symfony application I have a snippet that fetches data from the db but the last inserted record is the last in the view when the result is iterated through. Here is the snippet

EDITED

$restresults = $this->getDoctrine()->getRepository('myBundle:Images')->findAll();

How can I sort the above doctrine snippet in descending order whereby the last inserted becomes the first record.

2 answers

  • answered 2018-01-11 20:51 Bohdan Vovchuck

    The second param is for order:

    $messages = $em->getRepository("myBundle:Comments")->findBy(
        array(
            "imagefk" => $image
        ),
        array('id' => 'DESC')
    );
    

  • answered 2018-01-11 20:51 wonde

    assuming you have id column

    $restresults = $this->getDoctrine()->getRepository('myBundle:Images')->findBy([], ['id' => 'DESC']);