按日期时间symfony 2的订单数据

时间:2019-05-22 15:16:54

标签: php symfony doctrine symfony-2.7

我有一个数组,该数组包含要使用日期类型的属性“ CreatedAt”按日期显示数据的数据(列表顶部的新数据)。 这是我的控制器

{
    $em = $this->getDoctrine()->getManager();
    $user= $this->get('security.context')->getToken()->getUser();
    $congesshows = $em->getRepository('appUserBundle:Conges')
        ->findBy(array(),array('CreatedAt'=>'DESC'))
    ;

    $role = $user->getRoles() ;
    if($role[0]== "ROLE_ADMIN") {
        $congess = $em->getRepository('appUserBundle:Conges')
            ->findBy( array('etat' => 'En cours'))
        ;
    }
    else {
        $congess = $em->getRepository('appUserBundle:Conges')
            ->findBy(array('etat' => 'En attente'))
        ;
    }

    return $this->render(
        'appUserBundle:interne:please.html.twig',
        array('conges' => $congess,'congesshows'=>$congesshows)
   );
}

1 个答案:

答案 0 :(得分:1)

您尝试过$congesshows = $em->getRepository('appUserBundle:Conges') ->createQueryBuilder(“c”)->orderBy(“CreatedAt”, 'DESC')->getQuery()->getResult() ;吗?