首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >按datetime Symfony 2排序数据

按datetime Symfony 2排序数据
EN

Stack Overflow用户
提问于 2019-05-22 23:16:54
回答 1查看 41关注 0票数 0

我有一个包含数据的数组。我希望使用类型为datetime的属性"CreatedAt“按日期显示数据(列表开头的新数据)。这是我的控制器:

代码语言:javascript
复制
{
    $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)
   );
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-23 02:10:34

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56260084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档