PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 20, 2022

[FIXED] Order data by datetime Symfony 2

 January 20, 2022     doctrine, php, symfony, symfony-2.7     No comments   

Issue

I have an array that contains data. I want to show my data by date (the new data at the head of the list) using the attribute "CreatedAt" which type is datetime. here's my controller:

{
    $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)
   );
}

Solution

Did you try $congesshows = $em->getRepository('appUserBundle:Conges') ->createQueryBuilder(“c”)->orderBy(“CreatedAt”, 'DESC')->getQuery()->getResult() ; ?



Answered By - slmder_h
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing