PHPackages                             sdelfi/yii2-sitemap-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. sdelfi/yii2-sitemap-module

ActiveYii2-extension[Parsing &amp; Serialization](/categories/parsing)

sdelfi/yii2-sitemap-module
==========================

Yii2 module for automatically generation XML Sitemap

1.4.3(4y ago)034MITPHP &gt;=5.4.0

Since Sep 29Compare

[ Source](https://github.com/sdelfi/yii2-sitemap-module)[ Packagist](https://packagist.org/packages/sdelfi/yii2-sitemap-module)[ RSS](/packages/sdelfi-yii2-sitemap-module/feed)WikiDiscussions Synced today

READMEChangelogDependencies (4)Versions (18)Used By (0)

XML Sitemap Module for Yii2
===========================

[](#xml-sitemap-module-for-yii2)

[![PHP version](https://camo.githubusercontent.com/1a3f57cfa327c9c4f2e5d3fa800d89840885208e5e7dc98b35f0b14a2bbc19ad/68747470733a2f2f62616467652e667572792e696f2f70682f7364656c6669253246796969322d736974656d61702d6d6f64756c652e737667)](http://badge.fury.io/ph/sdelfi%2Fyii2-sitemap-module)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/72cf8b60ffc72fad1b8180e1d11409e7fd2b309b0852d51e903259406a35f213/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7364656c66692f796969322d736974656d61702d6d6f64756c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sdelfi/yii2-sitemap-module/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/4b1f4f192b6a11aeb5384e47cb1793acf86ccaf9b19fc83777c1edd3147b97a9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7364656c66692f796969322d736974656d61702d6d6f64756c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sdelfi/yii2-sitemap-module/?branch=master)[![Build Status](https://camo.githubusercontent.com/5751b7577a57cf17c557ccdd886d570944ffb97cd418493d941170c08e4cf8d5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7364656c66692f796969322d736974656d61702d6d6f64756c652f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sdelfi/yii2-sitemap-module/build-status/master)

Yii2 module for automatically generating [XML Sitemap](http://www.sitemaps.org/protocol.html).

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

- Either run

```
php composer.phar require --prefer-dist "sdelfi/yii2-sitemap-module" "*"

```

or add

```
"sdelfi/yii2-sitemap-module" : "*"
```

to the `require` section of your application's `composer.json` file.

- Configure the `cache` component of your application's configuration file, for example:

```
'components' => [
    'cache' => [
        'class' => 'yii\caching\FileCache',
    ],
]
```

- Add a new module in `modules` section of your application's configuration file, for example:

```
'modules' => [
    'sitemap' => [
        'class' => 'sdelfi\sitemap\Module',
    ],
...
],
```

- Add confuguration for sitemap into components section:

```
'components' => [
    'robotsTxt' => [
        'class' => 'sdelfi\sitemap\RobotsTxt',
        'userAgent' => [
            // Disallow url for all bots
            '*' => [
                'Disallow' => [
                    ['/api/default/index'],
                ],
                'Allow' => [
                    ['/api/doc/index'],
                ],
            ],
            // Block a specific image from Google Images
            'Googlebot-Image' => [
                'Disallow' => [
                    // All images on your site from Google Images
                    '/',
                    // Files of a specific file type (for example, .gif)
                    '/*.gif$',
                ],
            ],
        ],
    ],
    'sitemap' => [
        'class' => 'sdelfi\sitemap\Sitemap',
        'models' => [
            // your models
            'app\modules\news\models\News',
            // or configuration for creating a behavior
            [
                'class' => 'app\modules\news\models\News',
                'behaviors' => [
                    'sitemap' => [
                        'class' => '\sdelfi\sitemap\behaviors\SitemapBehavior',
                        'scope' => function ($model) {
                            /** @var \yii\db\ActiveQuery $model */
                            $model->select(['url', 'lastmod']);
                            $model->andWhere(['is_deleted' => 0]);
                        },
                        'dataClosure' => function ($model) {
                            /** @var self $model */
                            return [
                                'loc' => Url::to($model->url, true),
                                'lastmod' => strtotime($model->lastmod),
                                'changefreq' => \sdelfi\sitemap\Sitemap::DAILY,
                                'priority' => 0.8
                            ];
                        }
                    ],
                ],
            ],
        ],
        'urls'=> [
            // your additional urls
            [
                'loc' => ['/news/default/index'],
                'changefreq' => \sdelfi\sitemap\Sitemap::DAILY,
                'priority' => 0.8,
                'news' => [
                    'publication'   => [
                        'name'          => 'Example Blog',
                        'language'      => 'en',
                    ],
                    'access'            => 'Subscription',
                    'genres'            => 'Blog, UserGenerated',
                    'publication_date'  => 'YYYY-MM-DDThh:mm:ssTZD',
                    'title'             => 'Example Title',
                    'keywords'          => 'example, keywords, comma-separated',
                    'stock_tickers'     => 'NASDAQ:A, NASDAQ:B',
                ],
                'images' => [
                    [
                        'loc'           => 'http://example.com/image.jpg',
                        'caption'       => 'This is an example of a caption of an image',
                        'geo_location'  => 'City, State',
                        'title'         => 'Example image',
                        'license'       => 'http://example.com/license',
                    ],
                ],
            ],
        ],
        'enableCache' => false, // default is true
        'enableGzip' => true, // default is false
        'cacheExpire' => 1, // 1 second. Default is 24 hours,
        'sortByPriority' => true, // default is false
    ],
],
```

- Add behavior in the AR models, for example:

```
use sdelfi\sitemap\behaviors\SitemapBehavior;

public function behaviors()
{
    return [
        'sitemap' => [
            'class' => SitemapBehavior::className(),
            /**'batchSize' => 100,*/
            'scope' => function ($model) {
                /** @var \yii\db\ActiveQuery $model */
                $model->select(['url', 'lastmod']);
                $model->andWhere(['is_deleted' => 0]);
            },
            'dataClosure' => function ($model) {
                /** @var self $model */
                return [
                    'loc' => Url::to($model->url, true),
                    'lastmod' => strtotime($model->lastmod),
                    'changefreq' => Sitemap::DAILY,
                    'priority' => 0.8
                ];
            }
        ],
    ];
}
```

- Add a new rule for `urlManager` of your application's configuration file, for example:

```
'urlManager' => [
    'rules' => [
        ['pattern' => 'sitemap-', 'route' => '/sitemap/default/index', 'suffix' => '.xml'],
        ['pattern' => 'sitemap', 'route' => 'sitemap/default/index', 'suffix' => '.xml'],
    ],
],
```

Console generate sitemap
------------------------

[](#console-generate-sitemap)

Remove sitemap section from modules configuration.

Add console command configuration:

```
    'controllerMap' => [
        'sitemap' => [
            'class' => 'sdelfi\sitemap\console\CreateController',
        ],
    ],
```

Add baseUrl for urlManager:

```
     'urlManager' => [
         'baseUrl' => '',
         'hostInfo' => 'http://example.com/',
     ],
```

Run command from console:

```
$ ./yii sitemap/create
```

Resources
---------

[](#resources)

- [XML Sitemap](http://www.sitemaps.org/protocol.html)
- [News Sitemap](https://support.google.com/news/publisher/answer/74288?hl=en)
- [Image sitemaps](https://support.google.com/webmasters/answer/178636?hl=en)

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 76.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~164 days

Recently: every ~325 days

Total

16

Last Release

1822d ago

PHP version history (2 changes)1.3.0PHP &gt;=5.6.0

1.3.3PHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1927032?v=4)[Stanislav](/maintainers/sdelfi)[@sdelfi](https://github.com/sdelfi)

---

Top Contributors

[![serge-larin](https://avatars.githubusercontent.com/u/6086715?v=4)](https://github.com/serge-larin "serge-larin (129 commits)")[![himiklab](https://avatars.githubusercontent.com/u/6266409?v=4)](https://github.com/himiklab "himiklab (19 commits)")[![execut](https://avatars.githubusercontent.com/u/2357407?v=4)](https://github.com/execut "execut (10 commits)")[![sdelfi](https://avatars.githubusercontent.com/u/1927032?v=4)](https://github.com/sdelfi "sdelfi (4 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (4 commits)")[![ladamalina](https://avatars.githubusercontent.com/u/2093425?v=4)](https://github.com/ladamalina "ladamalina (2 commits)")[![chuprik](https://avatars.githubusercontent.com/u/802946?v=4)](https://github.com/chuprik "chuprik (1 commits)")

---

Tags

xmlyii2moduleSitemap

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/sdelfi-yii2-sitemap-module/health.svg)

```
[![Health](https://phpackages.com/badges/sdelfi-yii2-sitemap-module/health.svg)](https://phpackages.com/packages/sdelfi-yii2-sitemap-module)
```

###  Alternatives

[presta/sitemap-bundle

A Symfony bundle that provides tools to build your application sitemap.

3839.8M35](/packages/presta-sitemap-bundle)[demi/sitemap-generator

Yii2 component for generate sitemap.xml files.

1427.7k](/packages/demi-sitemap-generator)[light/yii2-xmlparser

yii2 xml request parser

1975.4k](/packages/light-yii2-xmlparser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
