Voici votre URL de partage https://sharemycode.io/c/2e92903 (Cliquer pour copier) (Copié)
Nom du fichier : SitemapController.php
<?php
namespace App\Controller;
use App\Repository\ActualityArticleRepository;
use App\Repository\ProductTaxonRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class SitemapController extends AbstractController
{
#[Route('/sitemap.xml', name: 'app_sitemap', defaults: ['_format' => 'xml'])]
public function index(Request $request, ActualityArticleRepository $actualityArticleRepository, ProductTaxonRepository $productTaxonRepository)
{
$articles = $actualityArticleRepository->findEnabledArticles($request->getLocale());
$categories = $productTaxonRepository->findTaxonWithProductsEnabled();
$hostname = $request->getSchemeAndHttpHost();
$urls = [];
$urls[] = ['loc' => $this->generateUrl('sylius_shop_homepage')];
$urls[] = ['loc' => $this->generateUrl('app_about_us_index')];
$urls[] = ['loc' => $this->generateUrl('app_legal_notice_index')];
$urls[] = ['loc' => $this->generateUrl('app_term_index')];
$urls[] = ['loc' => $this->generateUrl('app_privacy_index')];
$urls[] = ['loc' => $this->generateUrl('app_faq_index')];
$urls[] = ['loc' => $this->generateUrl('app_shipping_index')];
$urls[] = ['loc' => $this->generateUrl('app_contact_index')];
$urls[] = ['loc' => $this->generateUrl('app_newsletter_index')];
$urls[] = ['loc' => $this->generateUrl('app_actuality_index')];
$urls[] = ['loc' => $this->generateUrl('app_actuality_articles')];
foreach ($articles as $article)
{
foreach ($article->getImages()->getOwner()->getImages() as $articleImage)
{
$path = $articleImage->getPath();
$images = [
'loc' => '/media/image/' . $path
];
dump($images);
}
$urls[] = [
'loc' => $this->generateUrl('app_actuality_show', [
'slug' => $article->getSlug(),
]),
'lastmod' => $article->getUpdatedAt()->format('Y-m-d'),
'image' => $images
];
}
dd($urls);
$urls[] = ['loc' => $this->generateUrl('app_shop_index')];
foreach ($categories as $category)
{
$urls[] = [
'loc' => $this->generateUrl('sylius_shop_product_index', [
'slug' => $category->getTaxon()->getSlug(),
]),
];
}
$response = new Response(
$this->renderView('sitemap/index.html.twig', [
'urls' => $urls,
'hostname' => $hostname,
'articles' => $articles,
'categories' => $categories
])
);
$response->headers->set('Content-Type', 'text/xml');
return $response;
}
}
Informations
Cet extrait a été créé le 25 janv. 2023 à 10:03:01
Cet extrait expire le 24 févr. 2023 à 10:03:01
Langage : php
Link
Voici votre URL de partage : https://sharemycode.io/c/2e92903 Copié
Demander la suppression