Faire un count avec Doctrine2 dans Symfony2

Comment retourner un Count basique avec le Query Builder Doctrine 2 dans Symfony2.

return $this->createQueryBuilder('a')
 ->select('COUNT(a)')
 ->getQuery()
 ->getSingleScalarResult();

Note: getSingleScalarResult permet de ne retourner qu’une seule valeur.

25 réflexions au sujet de « Faire un count avec Doctrine2 dans Symfony2 »

  1. je ne comprend pas le mien return la requete sur la vue elle me donne ceci
    NB: SELECT COUNT(a) FROM EspaceProBundle:Espacepro a alors qu’elle devrait me retourner des chiffres.

  2. Je recommande plutôt ce code qui utilise la fonction count du queryBuilder.

    $queryBuilder = $this->createQueryBuilder(‘f’);
    $queryBuilder->select($queryBuilder->expr()->count(‘f’));
    $queryBuilder->where(‘f.user = :user’)->setParameter(‘user’, $user);

    $query = $queryBuilder->getQuery();
    $singleScalar = $query->getSingleScalarResult();
    return $singleScalar;

  3. Good day! Exceptional article! I adore how you described Faire un count avec Doctrine2 dans Symfony2 .
    Very worthwhile procedure of meals Faire un count avec Doctrine2 dans Symfony2 .
    Good place of employment! Here’s a very good write-up
    .
    Really bad I’m not really that great at website writing, especially in educational creating articles.
    That’s reason whyI normally organization petition of several creation merchants .

    But, ways, it’s of the big problem word of mouth
    about this subject web property best custom writing service reviews – Heriberto,.
    It may be a review corporate which often principal basis is to always evaluate writing establishments and look at the number
    of their merchandise

  4. Bonsoir sava bien jesper besoin d’aide je suis debutant Ssur Symfony et je travail sur un projet de gestion d’école mon probleme est ;
    j aimerai faire une requete qui permet de me d’affiche le nombre de garçon et filles d »une classe et mettre effectif total c’est a dire faire la somme des gerçon et filles
    c urgent Merci

  5. Ever thought if it’s attainable to drive costless traffic to your website, especially if you’re lost on where to start online?

    I am a Digital Marketing Specialist with SEO Spy company.

    I have been tracking Your Company and have been taken with your stellar website. Nonetheless, we are convinced that there’s forever opportunity for growth, especially in the virtual realm.

    From our expertise, effective backlinking stands as a vital part in improving a website’s SEO. Effectively implemented backlinks can:

    - Enhance your website’s SEO ranking
    - Boost targeted traffic and enhance sales
    - Create your brand’s reputation and reliability in the industry

    Employing our proven backlinking methods, we support businesses like Your Business grow their web visibility and in turn realize greater ROI.

    Are you amenable to discussing how Your Company might help Your Company in leveraging the effectiveness of backlinks to enhance your website’s performance?

    Eager forward to hearing your thoughts and possibly partnering together to elevate Your Company to new heights in the digital space.

    Let’s start on boosting your website’s performance immediately. Book a complimentary consultation with us today to learn additional about how we could optimize your digital reach and accelerate increased results for Your Company. Just look here – > https://tinyurl.com/seospybacklinks
    Don’t lose this opportunity to bring your company to the subsequent level!
    To your success,

Répondre à HenryPhima Annuler la réponse.

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

*

Vous pouvez utiliser ces balises et attributs HTML : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>