prestaconcept / PrestaSitemapBundle

A symfony bundle that provides tools to build a rich application sitemap. The main goals are : simple, no databases, various namespace (eg. google image), respect constraints etc.
MIT License
355 stars 102 forks source link

Section Option not Generating Routes? #230

Closed frodosghost closed 4 years ago

frodosghost commented 4 years ago

Having a problem with the section variable when setting up the sitemap bundle using annotations. Wondering where I am going wrong, any advice?

Route setup is below:

/**
 * @Route("/", name="app_registration_register",
 *     options={"sitemap" = {"priority" = 1, "changefreq" = "monthly", "section"="account"}}
 * )
 */

In the base sitemapindex the link to the section displays.

<sitemap>
    <loc>http://localhost:8080/sitemap.account.xml</loc>
    <lastmod>2020-02-28T23:14:19+00:00</lastmod>
</sitemap>

Visiting the URL generated returns a 404.

<response>
    <type>https://tools.ietf.org/html/rfc2616#section-10</type>
    <title>An error occurred</title>
    <status>404</status>
    <detail>Not found</detail>
    <class>
        Symfony\Component\HttpKernel\Exception\NotFoundHttpException
    </class>
    <trace>
        <namespace/>
        <short_class/>
        <class/>
        <type/>
        <function/>
        <file>
            /vagrant/vendor/presta/sitemap-bundle/Controller/SitemapController.php
        </file>
        <line>79</line>
        <args/>
    </trace>
    <trace>
        <namespace>Presta\SitemapBundle\Controller</namespace>
        <short_class>SitemapController</short_class>
        <class>Presta\SitemapBundle\Controller\SitemapController</class>
        <type>
            <![CDATA[ -> ]]>
        </type>
        <function>sectionAction</function>
        <file>/vagrant/vendor/symfony/http-kernel/HttpKernel.php</file>
        <line>145</line>
        <args/>
    </trace>
    <trace>
        <namespace>Symfony\Component\HttpKernel</namespace>
        <short_class>HttpKernel</short_class>
        <class>Symfony\Component\HttpKernel\HttpKernel</class>
        <type>
            <![CDATA[ -> ]]>
        </type>
        <function>handleRaw</function>
        <file>/vagrant/vendor/symfony/http-kernel/HttpKernel.php</file>
        <line>67</line>
        <args/>
    </trace>
    <trace>
        <namespace>Symfony\Component\HttpKernel</namespace>
        <short_class>HttpKernel</short_class>
        <class>Symfony\Component\HttpKernel\HttpKernel</class>
        <type>
            <![CDATA[ -> ]]>
        </type>
        <function>handle</function>
        <file>/vagrant/vendor/symfony/http-kernel/Kernel.php</file>
        <line>191</line>
        <args/>
    </trace>
    <trace>
        <namespace>Symfony\Component\HttpKernel</namespace>
        <short_class>Kernel</short_class>
        <class>Symfony\Component\HttpKernel\Kernel</class>
        <type>
            <![CDATA[ -> ]]>
        </type>
        <function>handle</function>
        <file>/vagrant/public/index.php</file>
        <line>37</line>
        <args/>
    </trace>
</response>
yann-eugone commented 4 years ago

Hello ! I believe that account is not the default section. Can you try to add an event listener like this one to your project :

    account.sitemap_listener:
        class: Presta\SitemapBundle\EventListener\RouteAnnotationEventListener
        arguments : 
            - '@router'
            - 'account'
        tags: ['kernel.event_listener']

Does it help ?

frodosghost commented 4 years ago

Thanks for the response. This suggested change does work, but moves all of the default routes into the account section.

I believe that account is not the default section.

@yann-eugone :: Correct. default is still the default section. Was looking at adding another section, so that we could have multiple sections for specific routes.

Is there a way to use multiple sections, defined by annotations?

yann-eugone commented 4 years ago

I thought it was possible, but recently I figured out that it is not...

By now, the only way to do it is to register these static routes by yourself in a custom event listener.

It is clearly a bug, and I'm not sure to understand why this is not possible. I was planning to work on a fix on this for the next release.

yann-eugone commented 4 years ago

Can you try #231 ?

composer require presta/sitemap-bundle:dev-multiple-static-sections@dev
frodosghost commented 4 years ago

@yann-eugone :: It does work. Does exactly what is needed.

yann-eugone commented 4 years ago

Released in v2.1.0