PHP code example of jantaodev / sitemap-bundle

1. Go to this page and download the library: Download jantaodev/sitemap-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/ */

    

jantaodev / sitemap-bundle example snippets


...
public function registerBundles()
{
    $bundles = array(
        ...
        new JantaoDev\SitemapBundle\JantaoDevSitemapBundle(),
        ...
    );
...

/**
 * @Route("/", name="homepage", options={"sitemap" = true})
 */

/**
 * @Route("/", name="homepage", options={"priority" = 0.5, "changeFreq" = "monthly", "lastMod" = "2017-02-23T13:14:15+02:00" })
 */

$this->get('jantao_dev.sitemap')->generate();



namespace AppBundle\EventListener;

use JantaoDev\SitemapBundle\Service\SitemapListenerInterface;
use JantaoDev\SitemapBundle\Event\SitemapGenerateEvent;
use JantaoDev\SitemapBundle\Sitemap\Url;

class SomeListener implements SitemapListenerInterface
{

    public function generateSitemap(SitemapGenerateEvent $event)
    {
        $sitemap = $event->getSitemap();

        $url = new Url('/index.php', new \DateTime('now'), 0.8, 'weekly');
        $sitemap->add($url);
    }
    
}

yaml
jantao_dev_sitemap:
    ...
    sitemap:
        homepage:
            iterator: array
            values:
                - slugone
                - slugtwo
                - slugthree
            priority: 0.5
            change_freq: monthly
            last_mod: "2017-02-23T13:14:15+02:00"
            route_parameters:
                slug: "->"
yaml
jantao_dev_sitemap:
    ...
    sitemap:
        homepage:
            iterator: array
            values:
                - {slug: slugone, change: monthly}
                - {slug: slugtwo, change: hourly}
                - {slug: slugthree, change: dayly}
            priority: 0.5
            change_freq: "->change"
            last_mod: "2017-02-23T13:14:15+02:00"
            route_parameters:
                slug: "->slug"