Search by

itstructure / yii2-sitemap-generator

itstructure

Yii2 component for generate sitemap.xml files.

Package info

github.com/itstructure/yii2-sitemap-generator

Type:yii2-extension

pkg:composer/itstructure/yii2-sitemap-generator

Statistics

Installs: 270

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2026-12-02 15:40 UTC

This package is auto-updated.

Last update: 2026-12-02 15:41:26 UTC


README

Yii2 component for generation sitemap.xml

It is reworked package, based on Dreamjobs yii2 sitemap generator

Status: the package is stable and is in maintenance mode: it is kept compatible with new PHP versions, only bug fixes are made.

Installation

Run command

composer require itstructure/yii2-sitemap-generator "~1.0.1"

Configuration

Set in "./console/config/main.php"

return [
    'controllerMap' => [
        'sitemap' => [
            'class' => 'Itstructure\Sitemap\SitemapController',
            'baseUrl' => 'https://example.com',
            'modelsPath' => '@console/models/sitemap', // Sitemap-data models directory
            'modelsNamespace' => 'console\models\sitemap', // Namespace in [[modelsPath]] files
            'savePathAlias' => '@frontend/web', // Where would be placed the generated sitemap-files
            'sitemapFileName' => 'sitemap.xml', // Name of main sitemap-file in [[savePathAlias]] directory
        ],
    ],
];

Set in "./environments/prod/console/config/main-local.php"

'components' => [
    // fix console create url
    'urlManager' => [
        'baseUrl' => 'http://example.com',
    ],
],

Set in "./environments/dev/console/config/main-local.php"

'components' => [
    // fix console create url
    'urlManager' => [
        'baseUrl' => 'http://example.local',
    ],
],

Run command

php ./init

OR just apply same config to your "/console/config/main-local.php"

ALSO you can merge urlManager rules from frontend(or common) to console config. Just change "/console/config/main.php" file:

// get config of urlManager from frontend for correctly create urls in console app
$frontend = require(__DIR__ . '/../../frontend/config/main.php');
$frontendUrlManager = [
    'components' => [
        'urlManager' => $frontend['components']['urlManager'],
    ],
];

// ...

// Merge frontend urlManager config with console application main config
return yii\helpers\ArrayHelper::merge($frontendUrlManager, [
    'id' => 'app-console',
    // ...
];

Also useful append .gitignore for ignore all generated sitemaps files:

# sitemaps
/frontend/web/sitemap*.xml

TBD: creating sitemap-data models

Usage

Run Yii console command in project root:

php ./yii sitemap

License

Copyright © 2020-2026 Andrey Girnik girnikandrey@gmail.com.

The package is based on Dreamjobs yii2 sitemap generator (author Ivan Orlov), which is licensed under the GNU General Public License v2.0. So this package is licensed under the same GNU GPL v2.0 license. See LICENSE for details.