PHP code example of xorgxx / neox-seo-bundle

1. Go to this page and download the library: Download xorgxx/neox-seo-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xorgxx / neox-seo-bundle example snippets


Bundles.php


return [
    .....
    NeoxSeo\NeoxSeoBundle\neoxSeoBundle::class => ['all' => true],
    .....
];

    myController.php
    
    
    use NeoxSeo\NeoxSeoBundle\Attribute\NeoxSeo;
    ....
    
    #[NeoxSeo( title: 'home page', charset: 'UTF-8', metasHttpEquiv: ['Content-Type'=>'text/html; charset=utf-4', 'Accept'=>'text/html; charset=utf-8'])]
    class HomeController extends _CoreController
    {
            #[Route('/{id}/send', name: 'app_admin_tokyo_crud_send', methods: ['GET'])]
            #[NeoxSeo( title: 'home index', metasName: ['keywords' =>'bar', 'description' => 'foo', 'robots' => 'index,follow'])]
            public function index( Request $request): Response
            {
                ....
            }


    myController.php
    
    #[NeoxSeo( title: 'home page', charset: 'UTF-8', metasHttpEquiv: ['Content-Type'=>'text/html; charset=utf-4', 'Accept'=>'text/html; charset=utf-8'])]
    class HomeController extends _CoreController
    {
          /**
           * @param NeoxSeoService $neoxSeoService
           *
           * @return Response
           */
           
            #[Route('/{id}/send', name: 'app_admin_tokyo_crud_send', methods: ['GET'])]
            #[NeoxSeo( title: 'home index', metasName: ['keywords' =>'bar', 'description' => 'foo', 'robots' => 'index,follow'])]
            public function index(NeoxSeoService $neoxSeoService): Response
            {
                $neoxSeoService->getSeoBag()
                  ->setTitle("home-page")
                  ->setMetasHttpEquiv([
                      'Content-Type'=>'text/html; charset=utf-56',
                      'Accept'=>'text/html; charset=utf-8',
                      'capnord'=>'text/html; charset=utf-8',
                 ])
                 ;
            }
            .....


use NeoxSeo\NeoxSeoBundle\Attribute\NeoxSitemap;

class PageController extends AbstractController
{
    #[Route('/about', name: 'app_about')]
    #[NeoxSitemap(priority: 0.8, changefreq: 'monthly')]
    public function about(): Response
    {
        // This page will automatically appear in /sitemap.xml
        return $this->render('page/about.html.twig');
    }

    #[Route('/contact', name: 'app_contact')]
    #[NeoxSitemap(priority: 0.6, changefreq: 'yearly')]
    public function contact(): Response
    {
        // This one too
        return $this->render('page/contact.html.twig');
    }
}

namespace App\Sitemap;

use NeoxSeo\NeoxSeoBundle\Sitemap\SitemapProviderInterface;
use App\Repository\ProductRepository;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class ProductSitemapProvider implements SitemapProviderInterface
{
    public function __construct(
        private readonly ProductRepository $productRepository,
        private readonly UrlGeneratorInterface $urlGenerator,
    ) {}

    public function getUrls(): array
    {
        $products = $this->productRepository->findAll();
        $urls = [];

        foreach ($products as $product) {
            $urls[] = [
                'loc'        => $this->urlGenerator->generate('app_product_show', ['id' => $product->getId()], UrlGeneratorInterface::ABSOLUTE_URL),
                'lastmod'    => $product->getUpdatedAt()->format('Y-m-d'),
                'changefreq' => 'weekly',
                'priority'   => 0.7,
            ];
        }

        return $urls;
    }
}

use NeoxSeo\NeoxSeoBundle\Attribute\NeoxBreadcrumb;

class ProductController extends AbstractController
{
    // Route: app_produits → /produits
    // No parent route with breadcrumb → Breadcrumb: Accueil > Produits
    #[Route('/produits', name: 'app_produits')]
    #[NeoxBreadcrumb(label: 'Produits')]
    public function produits(): Response
    {
        return $this->render('product/list.html.twig');
    }

    // Route: app_produits_boite → /produits/boite
    // Auto-deduction: app_produits_boite → app_produits (has #[NeoxBreadcrumb] "Produits")
    // Breadcrumb: Accueil > Produits > Boîte
    #[Route('/produits/boite', name: 'app_produits_boite')]
    #[NeoxBreadcrumb(label: 'Boîte')]
    public function boite(): Response
    {
        return $this->render('product/boite.html.twig');
    }

    // Route: app_produits_boite_pizza → /produits/boite/pizza
    // Auto-deduction: app_produits_boite_pizza → app_produits_boite → app_produits
    // Breadcrumb: Accueil > Produits > Boîte > Pizza
    #[Route('/produits/boite/pizza', name: 'app_produits_boite_pizza')]
    #[NeoxBreadcrumb(label: 'Pizza')]
    public function pizza(): Response
    {
        return $this->render('product/pizza.html.twig');
    }
}

// Route: app_catalog_special → /catalog/special
// Auto-deduction: app_catalog_special → app_catalog → doesn't exist → stop
// Override: parent: 'app_produits' forces "Produits" as parent
#[Route('/catalog/special', name: 'app_catalog_special')]
#[NeoxBreadcrumb(label: 'Spécial', parent: 'app_produits')]
public function special(): Response
{
    // Breadcrumb: Accueil > Produits > Spécial
    return $this->render('catalog/special.html.twig');
}

// app_produits has #[NeoxBreadcrumb(label: 'Produits')]
// This route would auto-deduct "Produits" as parent, but we don't want a breadcrumb here
#[Route('/produits/api', name: 'app_produits_api')]
#[NeoxBreadcrumb(enabled: false)]
public function api(): Response
{
    // No breadcrumb at all on this page — not even "Accueil > Produits"
    return $this->json([...]);
}

use NeoxSeo\NeoxSeoBundle\Breadcrumb\BreadcrumbService;

class ProductController extends AbstractController
{
    // URL: /produits/{id}
    // Breadcrumb: Accueil > Produits > Fond pizza
    #[Route('/produits/{id}', name: 'app_product_show')]
    public function show(BreadcrumbService $breadcrumb, Product $product): Response
    {
        // addRoute() = clickable item (generates URL from route name)
        $breadcrumb->addRoute('Produits', 'app_produits');

        // add() = plain text item (last item, not clickable)
        $breadcrumb->add($product->getName());

        return $this->render('product/show.html.twig', ['product' => $product]);
    }
}

// Route: app_produits_show → /produits/{id}
// Auto-deduction: app_produits_show → app_produits → "Produits"
#[Route('/produits/{id}', name: 'app_produits_show')]
#[NeoxBreadcrumb(label: '')]  // label will be overridden by injection
public function show(BreadcrumbService $breadcrumb, Product $product): Response
{
    // Parent "Produits" was auto-deduced from app_produits
    // Now add the dynamic product name as the last item
    $breadcrumb->add($product->getName());
}

#[Route('/', name: 'seo_home')]
public function index(): Response { ... }

#[Route('/contact', name: 'seo_contact')]
public function contact(): Response { ... }
yaml
neox_seo:
    sitemap:
        enabled: true
        mode: "on_demand"       # "on_demand" = route /sitemap.xml, "static" = CLI only
        route: "/sitemap.xml"
        defaults:
            changefreq: "weekly"
            priority: 0.5
        exclude_patterns:
            - "/_profiler"
            - "/_wdt"
            - "/admin/*"
bash
php bin/console neox:seo:sitemap:generate
# Writes to public/sitemap.xml by default

php bin/console neox:seo:sitemap:generate --output=public/sitemap.xml