Bundle/BlogBundle/Controller/BlogController.php
public function feedAction(Request $request, Blog $blog)
    {
        $articles = $blog->getPublishedArticles();
        if ($categoryId = $request->query->get('category')) {
            $entityManager = $this->getDoctrine()->getManager();
            /** @var Category $category */
            $category = $entityManager->getRepository('VictoireBlogBundle:BlogCategory')->find($categoryId);
            $categoryIds = [];

            function findIds(BlogCategory $category, &$categoryIds)
            {
                $categoryIds[] = $category->getId();

                foreach ($category->getChildren() as $childCategory) {
                    findIds($childCategory, $categoryIds);
                }
            }

            findIds($category, $categoryIds);

            $articles = $articles->filter(function ($article) use ($categoryIds) {
                /* @var Article $article */
                return $article->getCategory() && in_array($article->getCategory()->getId(), $categoryIds, true);
            });
        }

        return $this->render('VictoireBlogBundle:Blog:feed.rss.twig', [
            'blog'     => $blog,
            'articles' => $articles,
        ]);
    }
public function feedAction(Request $request, Blog $blog)
    {
        $articles = $blog->getPublishedArticles();
        if ($categoryId = $request->query->get('category')) {
            $entityManager = $this->getDoctrine()->getManager();
            /** @var Category $category */
            $category = $entityManager->getRepository('VictoireBlogBundle:BlogCategory')->find($categoryId);
            $categoryIds = [];

            function findIds(BlogCategory $category, &$categoryIds)
            {
                $categoryIds[] = $category->getId();

                foreach ($category->getChildren() as $childCategory) {
                    findIds($childCategory, $categoryIds);
                }
            }

            findIds($category, $categoryIds);

            $articles = $articles->filter(function ($article) use ($categoryIds) {
                /* @var Article $article */
                return $article->getCategory() && in_array($article->getCategory()->getId(), $categoryIds, true);
            });
        }

        return $this->render('VictoireBlogBundle:Blog:feed.rss.twig', [
            'blog'     => $blog,
            'articles' => $articles,
        ]);
    }
public function feedAction ( Request $ request , Blog $ blog ) { $ articles = $ blog -> getPublishedArticles ( ) ; if ( $ categoryId = $ request -> query -> get ( 'category' ) ) { $ entityManager = $ this -> getDoctrine ( ) -> getManager ( ) ; /** @var Category $category */ $ category = $ entityManager -> getRepository ( 'VictoireBlogBundle:BlogCategory' ) -> find ( $ categoryId ) ; $ categoryIds = [ ] ; function findIds ( BlogCategory $ category , & $ categoryIds ) { $ categoryIds [ ] = $ category -> getId ( ) ; foreach ( $ category -> getChildren ( ) as $ childCategory ) { findIds ( $ childCategory , $ categoryIds ) ; } } findIds ( $ category , $ categoryIds ) ; $ articles = $ articles -> filter ( function ( $ article ) use ( $ categoryIds ) { /* @var Article $article */ return $ article -> getCategory ( ) && in_array ( $ article -> getCategory ( ) -> getId ( ) , $ categoryIds , true ) ; } ) ; } return $ this -> render ( 'VictoireBlogBundle:Blog:feed.rss.twig' , [ 'blog' => $ blog , 'articles' => $ articles , ] ) ; }
Display Blogs RSS feed.

@Route("/feed/{id}.rss", name="victoire_blog_rss", defaults={"_format" = "rss"})

@param Request $request

@return Response
Display Blogs RSS feed .