按降序排序表记录 - symfony

时间:2018-01-11 20:51:57

标签: php mysql symfony

我在db中有一个记录表,其中最后插​​入的记录是表记录行中的最后一个。在我的symfony应用程序中,我有一个从数据库中获取数据的片段,但最后插入的记录是迭代结果时视图中的最后一个。这是片段

EDITED

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

如何按降序对上述doctrine片段进行排序,最后插入的片段成为第一个记录。

2 个答案:

答案 0 :(得分:1)

第二个参数是订单:

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

答案 1 :(得分:1)

假设您有id列

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