Controller/SitemapController.php
public function indexAction()
    {
        $searchService = $this->get( "ezpublish.api.repository" )->getSearchService();
        $query         = $this->getQuery();
        $query->limit  = 0;
        $resultCount   = $searchService->findLocations( $query )->totalCount;

        // Dom Doc
        $sitemap               = new DOMDocument( "1.0", "UTF-8" );
        $sitemap->formatOutput = true;

        // create an index if we are greater than th PACKET_MAX
        if ( $resultCount > static::PACKET_MAX )
        {
            $root = $sitemap->createElement( "sitemapindex" );
            $root->setAttribute( "xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9" );
            $sitemap->appendChild( $root );

            $this->fillSitemapIndex( $sitemap, $resultCount, $root );

            return new Response( $sitemap->saveXML(), 200, [ "Content-type" => "text/xml" ] );
        }

        // if we are less or equal than the PACKET_SIZE, redo the search with no limit and list directly the urlmap
        $query->limit = $resultCount;
        $results      = $searchService->findLocations( $query );
        $root         = $sitemap->createElement( "urlset" );
        $root->setAttribute( "xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9" );
        $this->fillSitemap( $sitemap, $root, $results );
        $sitemap->appendChild( $root );

        $response = new Response( $sitemap->saveXML(), 200, [ "Content-type" => "text/xml" ] );
        $response->setSharedMaxAge( 24 * 3600 );

        return $response;
    }
public function indexAction()
    {
        $searchService = $this->get( "ezpublish.api.repository" )->getSearchService();
        $query         = $this->getQuery();
        $query->limit  = 0;
        $resultCount   = $searchService->findLocations( $query )->totalCount;

        // Dom Doc
        $sitemap               = new DOMDocument( "1.0", "UTF-8" );
        $sitemap->formatOutput = true;

        // create an index if we are greater than th PACKET_MAX
        if ( $resultCount > static::PACKET_MAX )
        {
            $root = $sitemap->createElement( "sitemapindex" );
            $root->setAttribute( "xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9" );
            $sitemap->appendChild( $root );

            $this->fillSitemapIndex( $sitemap, $resultCount, $root );

            return new Response( $sitemap->saveXML(), 200, [ "Content-type" => "text/xml" ] );
        }

        // if we are less or equal than the PACKET_SIZE, redo the search with no limit and list directly the urlmap
        $query->limit = $resultCount;
        $results      = $searchService->findLocations( $query );
        $root         = $sitemap->createElement( "urlset" );
        $root->setAttribute( "xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9" );
        $this->fillSitemap( $sitemap, $root, $results );
        $sitemap->appendChild( $root );

        $response = new Response( $sitemap->saveXML(), 200, [ "Content-type" => "text/xml" ] );
        $response->setSharedMaxAge( 24 * 3600 );

        return $response;
    }
public function indexAction ( ) { $ searchService = $ this -> get ( "ezpublish.api.repository" ) -> getSearchService ( ) ; $ query = $ this -> getQuery ( ) ; $ query -> limit = 0 ; $ resultCount = $ searchService -> findLocations ( $ query ) -> totalCount ; // Dom Doc $ sitemap = new DOMDocument ( "1.0" , "UTF-8" ) ; $ sitemap -> formatOutput = true ; // create an index if we are greater than th PACKET_MAX if ( $ resultCount > static :: PACKET_MAX ) { $ root = $ sitemap -> createElement ( "sitemapindex" ) ; $ root -> setAttribute ( "xmlns" , "http://www.sitemaps.org/schemas/sitemap/0.9" ) ; $ sitemap -> appendChild ( $ root ) ; $ this -> fillSitemapIndex ( $ sitemap , $ resultCount , $ root ) ; return new Response ( $ sitemap -> saveXML ( ) , 200 , [ "Content-type" => "text/xml" ] ) ; } // if we are less or equal than the PACKET_SIZE, redo the search with no limit and list directly the urlmap $ query -> limit = $ resultCount ; $ results = $ searchService -> findLocations ( $ query ) ; $ root = $ sitemap -> createElement ( "urlset" ) ; $ root -> setAttribute ( "xmlns" , "http://www.sitemaps.org/schemas/sitemap/0.9" ) ; $ this -> fillSitemap ( $ sitemap , $ root , $ results ) ; $ sitemap -> appendChild ( $ root ) ; $ response = new Response ( $ sitemap -> saveXML ( ) , 200 , [ "Content-type" => "text/xml" ] ) ; $ response -> setSharedMaxAge ( 24 * 3600 ) ; return $ response ; }
Sitemaps.xml route

@Route("/sitemap.xml", name="_novaseo_sitemap_index")
@Method("GET")

@return Response
Sitemaps . xml route