Skip to content
Simple sitemap generator provider for Silex.
PHP Gherkin
Branch: release/4.x.x
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
features
src
.gitignore
.travis.yml
CONTRIBUTING.md
LICENSE
README.md
composer.json
composer.lock

README.md

silex-sitemap-service-provider

Build Status Latest Stable Version License Issues Total Downloads

The provider supports both major Versions of Silex.

Installation

For applications based on Silex >= 2.0.0:

composer require tm/silex-sitemap-service-provider ^4.0

If you use Silex 1.3.x or lower in your application:

composer require tm/silex-sitemap-service-provider ^3.0

Example Basic Usage

First you have to register the ServiceProvider:

    $app->register(new TM\Provider\SitemapServiceProvider());

Optional you can also set some options for the generator:

    $app->register(new TM\Provider\SitemapServiceProvider(), [
        'sitemap.options' => [
            'charset' => 'ISO-8859-1',
            'version' => '1.0',
            'scheme' => 'http://www.sitemaps.org/schemas/sitemap/0.8'
        ]
    ]);

Then implement the route for the sitemap.xml with your custom logic:

    $app->get('sitemap.xml', function () use ($app) {
  
      $host = $app['request']->getSchemeAndHttpHost();
      
      $sitemap = $app['sitemap'];
      $sitemap->addEntry($host . '/', 1, 'yearly');
      
      $entities = $app['repository.entity']->findAll(50000);
  
      foreach ($entities as $entity) {
        $entityLoc = $app['url_generator']->generate('entity', array('entity' => $entity->getId()));
        $sitemap->addEntry($host . $entityLoc, 0.8, 'monthly', $entity->getLastModified());
      }
  
      return $sitemap->generate();
    })
    ->bind('sitemap');

Contributing

Please refer to CONTRIBUTING.md for information on how to contribute.

Development

Run tests with the following command in the project directory.

composer install
./vendor/bin/behat 
You can’t perform that action at this time.