Symfony2, Doctrine2 - display items by Category with query

前端 未结 1 707

I\'m creating second route for display all articles by category in the URL. There is my route for that:

default_blog_category:
    path:     /category/{slug}         


        
1条回答
  •  离开以前
    2021-01-07 15:29

    You have to join the categories. This code should be placed in the ArticleRepository.

    $qb = $this->createQueryBuilder('a');
    $qb->add('select', 'a');
    $qb->leftJoin('a.category', 'c');
    $qb->where('c.name LIKE :category'); /* i have guessed a.name */
    $qb->setParameter('category', $slug);
    $qb->getQuery()->getResult();
    

    See doctrine query builder and symfony custom repository classes for an tutorial.

    0 讨论(0)
提交回复
热议问题