2017 © Pedro Peláez
 

yii2-extension yii2-sitemap-module

Yii2 module for automatically generation XML Sitemap

image

himiklab/yii2-sitemap-module

Yii2 module for automatically generation XML Sitemap

  • Tuesday, February 27, 2018
  • by HimikLab
  • Repository
  • 9 Watchers
  • 67 Stars
  • 31,654 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 37 Forks
  • 2 Open issues
  • 5 Versions
  • 9 % Grown

The README.md

XML Sitemap Module for Yii2

Yii2 module for automatically generating XML Sitemap., (*1)

Packagist Packagist license, (*2)

Installation

The preferred way to install this extension is through composer., (*3)

  • Either run
php composer.phar require --prefer-dist "himiklab/yii2-sitemap-module" "*"

or add, (*4)

"himiklab/yii2-sitemap-module" : "*"

to the require section of your application's composer.json file., (*5)

  • Configure the cache component of your application's configuration file, for example:
'components' => [
    'cache' => [
        'class' => 'yii\caching\FileCache',
    ],
]
  • Add use himiklab\sitemap\behaviors\SitemapBehavior; to the beginning of configuration file, (*6)

  • Add a new module in modules section of your application's configuration file, for example:, (*7)

'modules' => [
    'sitemap' => [
        'class' => 'himiklab\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' => SitemapBehavior::className(),
                            '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' => SitemapBehavior::CHANGEFREQ_DAILY,
                                    'priority' => 0.8,
                                    'xhtml:link' => [
                                        [
                                            'hreflang' => 'en',
                                            'href' => Url::to(['url_en'], true),
                                        ],
                                        [
                                            'hreflang' => 'de',
                                            'href' => Url::to(['url_de'], true),
                                        ],
                                        //...
                                    ],
                                ];
                            }
                        ],
                    ],
                ],
            ],
        ],
        'urls'=> [
            // your additional urls
            [
                'loc' => '/news/index',
                'changefreq' => SitemapBehavior::CHANGEFREQ_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',
                    ],
                ],
            ],
        ],
        'enableGzip' => true, // default is false
        'cacheExpire' => 1, // 1 second. Default is 24 hours
    ],
],
  • Add behavior in the AR models, for example:
use himiklab\sitemap\behaviors\SitemapBehavior;

public function behaviors()
{
    return [
        'sitemap' => [
            'class' => SitemapBehavior::className(),
            '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' => SitemapBehavior::CHANGEFREQ_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'],
    ],
],

Resources

The Versions

27/02 2018

dev-master

9999999-dev

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

xml yii2 module sitemap

08/11 2017

1.2.0

1.2.0.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

xml yii2 module sitemap

31/07 2015

1.1.2

1.1.2.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

xml yii2 module sitemap

26/01 2015

1.1.1

1.1.1.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

xml yii2 module sitemap

29/09 2014

1.0.0

1.0.0.0

Yii2 module for automatically generation XML Sitemap

  Sources   Download

MIT

The Requires

 

xml yii2 module sitemap