pendalf89/yii2-sitemap Yii2 sitemap component

Yii2 sitemap

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist pendalf89/yii2-sitemap "*"

or add

"pendalf89/yii2-sitemap": "*"

to the require section of your composer.json file.

Apply migration

yii migrate --migrationPath=vendor/pendalf89/yii2-sitemap/src/migrations

Configuration:

'components' => [
    'sitemap' => [
        'class' => 'pendalf89\sitemap\Sitemap',
        'sitemaps'  => [
                'frontend\sitemaps\ArticlesSitemap', // see example of class below
                'frontend\sitemaps\OtherSitemap', // see example of class below
            ],
        'generator' => [
            'class'   => 'pendalf89\sitemap\SitemapGenerator',
            'path'    => '@frontend/web',
            'baseUrl' => 'https://example.com',
        ],
    ],
],

Usage

In first, create sitemap classes, for example:

namespace frontend\sitemaps;

use pendalf89\sitemap\SitemapInterface;

class OtherSitemap implements SitemapInterface
{
    /**
     * @inheritdoc
     */
    public function getName()
    {
        return 'sitemap-other';
    }

    /**
     * @inheritdoc
     */
    public function getUrls()
    {
        return [
            ['loc' => '/any-url/'],
            ['loc' => '/any-url-width-date/', 'lastmod' => '2016-09-02 12:23:17'],
        ];
    }
}

So, when you create sitemap classes, you can use component for create sitemap files.

Yii::$app->sitemap->update();

Also, you can update one url in DB:

Yii::$app->sitemap->updateUrl('/any-url-width-date/', '2016-09-02 12:23:17');

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

No stable releases.

Comments



No stable releases.



MIT license
Stats
1 github stars & 1 github forks
0 downloads in the last day
0 downloads in the last 30 days
220 total downloads