keiii/silex-sitemap

Provides service for generate sitemap.xml

2.0.1 2016-12-05 07:55 UTC

This package is not auto-updated.

Last update: 2020-07-10 19:29:45 UTC


README

Build Status

Provides sitemap-php service for Silex microframework.

Installation

composer require keiii/silex-sitemap

How to use

<?php

require_once __DIR__.'/vendor/autoload.php';

$app = new \Silex\Application();
$app->register(new \KEIII\SilexSitemap\SitemapServiceProvider(), array(
    'sitemap.domain' => 'http://example.com',
    'sitemap.path' => __DIR__,
    'sitemap.loc' => 'http://example.com/',
));

/** @var \KEIII\SilexSitemap\Sitemap $sitemap */
$sitemap = $app['sitemap'];

for ($i = 0; $i < 51000; $i++) {
    $item = (new \KEIII\SilexSitemap\SitemapItem())
        ->setLoc('/')
        ->setPriority(1.0)
        ->setChangefreq('daily')
        ->setLastmod(new \DateTime())
    ;
    $sitemap->addItem($item);
}

$sitemap->create();

When you run your script, it generates and saves XML files to given path.