src/Controller/SitemapController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\ArticleRepository;
  4. use App\Repository\PhotoAlbumRepository;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class SitemapController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/sitemap.xml", name="sitemap", defaults={"_format"="xml"})
  12.      */
  13.     public function sitemap(
  14.         ArticleRepository $articleRepo,
  15.         PhotoAlbumRepository $albumRepo
  16.     ): Response {
  17.         $articles $articleRepo->findBy(['isActive' => true]);
  18.         $albums   $albumRepo->findBy(['isActive' => true]);
  19.         $response $this->render('sitemap.xml.twig', [
  20.             'articles' => $articles,
  21.             'albums'   => $albums,
  22.         ]);
  23.         $response->headers->set('Content-Type''application/xml; charset=UTF-8');
  24.         return $response;
  25.     }
  26. }