mima/yii2-sitemap-generator

Library for create and write sitemap.xml for you site. Yii2 implementation.

v1.0.2 2016-09-27 15:57 UTC

This package is auto-updated.

Last update: 2024-05-13 22:28:46 UTC


README

Build Status

This library is implementation of mima/sitemap-generator for yii2 framework. It delivers a custom component and writer based on yii2 features. Documentation about sitemap generator library you can find here.

Installation

Install with composer from command line:

composer require mima/yii2-sitemap-generator

Or add dependency to require section in your composer.json:

{
    "require": {
        "mima/yii2-sitemap-generator": "~1.0"
    }
}

Usage

Configure component on runtime:

use SitemapGenerator\Component\SitemapGeneratorComponent;
use SitemapGenerator\Factory\SimpleGeneratorFactory;
use MyNamespace\Extractor\MyDataExtractor;

\Yii::$app->set('sitemapGenerator', [
    'class' => SitemapGeneratorComponent::class,
    'directoryToSaveSitemap' => '@webroot',
    'fileName' => 'sitemap.xml',
    'extractor' => MyDataExtractor::class,
    'generatorFactory' => SimpleGeneratorFactory::class
]);

Configure in application config:

return [
    // ...
    'components' => [
        'sitemapGenerator' => [
            'class' => SitemapGenerator\Component\SitemapGeneratorComponent::class,
            'directoryToSaveSitemap' => '@webroot',
            'fileName' => 'sitemap.xml',
            'extractor' => MyNamespace\Extractor\MyDataExtractor::class,
            'generatorFactory' => SitemapGenerator\Factory\SimpleGeneratorFactory::class
        ]
    ]
    //...
];

The following are valid settings:

  • directoryToSaveSitemap - real path or yii alias to directory, where sitemap will be saved
  • fileName - name of sitemap file
  • extractor - name of class instance of SitemapGenerator\Extractor\DataExtractorInterface
  • generatorFactory - name of class instance of SitemapGenerator\Factory\GeneratorFactoryInterface

For generating sitemap call generate method:

// This code generate sitemap and return path to file, containig sitemap
$filePath = \Yii::$app->get('sitemapGenerator')->generate();