<?php
namespace App\Controller;
use App\Repository\BienRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class SitemapController extends AbstractController
{
/**
* @Route("/sitemap.xml", name="sitemap", defaults={"_format"="xml"})
*/
public function index(
Request $request,
BienRepository $bienRepository
): Response {
$hostname = $request->getSchemeAndHttpHost();
$urls = [];
$urls[] = ['loc' => $this->generateUrl('app_about')];
$urls[] = ['loc' => $this->generateUrl('app_biens_index')];
$urls[] = ['loc' => $this->generateUrl('app_home')];
$urls[] = ['loc' => $this->generateUrl('app_contact')];
$urls[] = ['loc' => $this->generateUrl('app_equipe')];
$urls[] = ['loc' => $this->generateUrl('app_honoraires')];
$urls[] = ['loc' => $this->generateUrl('app_estimation')];
foreach($bienRepository->findAll() as $bien) {
$urls[] = [
'loc' => $this->generateUrl('app_biens_show', ['id' => $bien->getId()]),
'lastmod' => (new \DateTime())->format('Y-m-d')
];
}
$response = new Response(
$this->renderView('sitemap/index.html.twig', [
'urls' => $urls,
'hostname' => $hostname,
]),
200
);
$response->headers->set('Content-type', 'text/xml');
return $response;
}
}