PHPackages                             xj/yii2-sitemap - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. xj/yii2-sitemap

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

xj/yii2-sitemap
===============

yii2-sitemap

2.0.2(10y ago)142.7k8[1 issues](https://github.com/xjflyttp/yii2-sitemap/issues)BSD-3-ClausePHP

Since Aug 19Pushed 10y ago5 watchersCompare

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

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

yii2-sitemap
============

[](#yii2-sitemap)

Note
----

[](#note)

```
ver2.0+ Api has change.
Please read README

```

composer.json
-------------

[](#composerjson)

```
"require": {
    "xj/yii2-sitemap": "~2.0"
},
```

Actions
-------

[](#actions)

```
use app\models\User;
use yii\data\ActiveDataProvider;
use yii\data\ArrayDataProvider;
use xj\sitemap\models\Url;
use xj\sitemap\models\BaiduUrl;
use xj\sitemap\models\Image;
use xj\sitemap\models\News;
use xj\sitemap\actions\SitemapUrlsetAction;
use xj\sitemap\actions\SitemapIndexAction;

public function actions()
{
    return [
        //Google Sitemap By ActiveRecord
        'sitemap-google-index' => [
            'class' => SitemapIndexAction::className(),
            'route' => ['sitemap-google-urlset'],
            'dataProvider' => new ActiveDataProvider([
                'query' => User::find(),
                'pagination' => [
                    'pageParam' => 'p',
                    'pageSize' => 1, //per page 1 record
                ]]),
        ],
        'sitemap-google-urlset' => [
            'class' => SitemapUrlsetAction::className(),
            'gzip' => YII_DEBUG ? false : true,
            'dataProvider' => new ActiveDataProvider([
                'query' => User::find(),
                'pagination' => [
                    'pageParam' => 'p',
                    'pageSize' => 1,
                ]]),
            'remap' => function ($model) {
                    /* @var $model User */
                    $url = Url::create([
                        'loc' => \yii\helpers\Url::to(['user/view', 'username' => $model->username], true),
                        'lastmod' => date(DATE_W3C, $model->updated_at),
                        'changefreq' => Url::CHANGEFREQ_MONTHLY,
                        'priority' => '0.5',
                    ]);
                    //BEGIN AddImage
                    $url->addImage(new Image([
                        'loc' => 'http://example.com/image1.jpg',
                    ]));
                    $url->addImage(new Image([
                        'loc' => 'http://example.com/image2.jpg',
                        'caption' => 'caption of the image.',
                        'geo_location' => 'Limerick, Ireland',
                        'title' => 'The title of the image.',
                        'license' => 'A URL to the license of the image.',
                    ]));
                    //END AddImage
                    // I'm a SplitLine
                    //BEGIN AddNews
                    $url->addNews(new News([
                        'publication' => [
                            'name' => 'The Example Times',
                            'language' => 'en',
                        ],
                        'access' => 'Subscription',
                        'genres' => 'PressRelease, Blog',
                        'publication_date' => '2008-12-23',
                        'title' => 'Companies A, B in Merger Talks',
                        'keywords' => 'business, merger, acquisition, A, B',
                        'stock_tickers' => 'NASDAQ:A, NASDAQ:B',
                    ]));
                    //END AddNews
                    return $url;
            },
        ],

        //Baidu Mobile Sitemap By ActiveRecord
        'sitemap-baidumobile-index' => [
            'class' => SitemapIndexAction::className(),
            'route' => ['sitemap-baidumobile-urlset'],
            'dataProvider' => new ActiveDataProvider([
                'query' => User::find(),
                'pagination' => [
                    'pageParam' => 'p',
                    'pageSize' => 1, //per page 1 record
                ]]),
        ],
        'sitemap-baidumobile-urlset' => [
            'class' => SitemapUrlsetAction::className(),
            'urlClass' => BaiduUrl::className(), //for Baidu
            'gzip' => YII_DEBUG ? false : true,
            'dataProvider' => new ActiveDataProvider([
                'query' => User::find(),
                'pagination' => [
                    'pageParam' => 'p',
                    'pageSize' => 1,
                ]]),
            'remap' => function ($model) {
                /* @var $model User */
                //return Array will auto using $urlClass::create()
                return [
                    'loc' => \yii\helpers\Url::to(['user/view', 'username' => $model->username], true),
                    'lastmod' => date(DATE_W3C, $model->updated_at),
                    'changefreq' => Url::CHANGEFREQ_MONTHLY,
                    'priority' => '0.5',
                    'baiduType' => BaiduUrl::BAIDU_TYPE_MOBILE, // BaiduUrl::BAIDU_TYPE_ADAP | BaiduUrl::BAIDU_TYPE_HTMLADAP
                ];
            },
        ],

        //FOR DIRECT DATA
        'sitemap-direct-index' => [
            'class' => SitemapIndexAction::className(),
            'route' => ['sitemap-direct'],
            'dataProvider' => new ArrayDataProvider([
                'allModels' => [
                    1, 1, 1, 1 //only need number// p=1 | p=2 | p=3 | p=4
                ],
                'pagination' => [
                    'pageParam' => 'p',
                    'pageSize' => 1,
                ]
            ]),
        ],
        'sitemap-direct-urlset' => [
            'class' => SitemapUrlsetAction::className(),
            'gzip' => YII_DEBUG ? false : true,
            'dataProvider' => new ArrayDataProvider([
                'allModels' => [
                    [
                        'loc' => 'http://url-a',
                        'lastmod' => date(DATE_W3C),
                        'changefreq' => Url::CHANGEFREQ_ALWAYS,
                    ],
                    [
                        'loc' => 'http://url-b',
                        'lastmod' => date(DATE_W3C),
                        'changefreq' => Url::CHANGEFREQ_DAILY,
                    ],
                    [
                        'loc' => 'http://error-model',
                        'lastmod' => date(DATE_W3C),
                        'changefreq' => Url::CHANGEFREQ_HOURLY,
                        'priority' => 'errorPriority',
                    ],
                    [
                        'loc' => 'http://url-c',
                        'lastmod' => date(DATE_W3C),
                        'changefreq' => Url::CHANGEFREQ_HOURLY,
                    ],
                ],
                'pagination' => [
                    'pageParam' => 'p',
                    'pageSize' => 4,
                ]
            ]),
            'remap' => function ($model) {
                /* @var $model array */
                return Url::create()->setAttributes($model);
            },
        ],

    ];
}
```

UrlManager
----------

[](#urlmanager)

```
[
    'class' => 'yii\web\UrlManager',
    'showScriptName' => false,
    'enablePrettyUrl' => true,
    'rules' => [
        'sitemap.xml' => 'sitemap/sitemap-google-index',
        'sitemap..xml.gz' => 'sitemap/sitemap-google-urlset',
    ],
];
```

Access
------

[](#access)

```
http://domain/sitemap.xml
http://domain/sitemap.1.xml.gz

```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~122 days

Total

5

Last Release

3847d ago

Major Versions

1.1.0 → 2.0.02015-08-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/f9f04ccc1ccda3af80975323425ff7d5f7d142603f1ad05df6558ffa63256f8d?d=identicon)[xjflyttp](/maintainers/xjflyttp)

---

Top Contributors

[![xjflyttp](https://avatars.githubusercontent.com/u/128428?v=4)](https://github.com/xjflyttp "xjflyttp (10 commits)")

### Embed Badge

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

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)

PHPackages © 2026

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