dev-master
9999999-devYii2 module for automatically generation XML Sitemap
MIT
The Requires
- php >=5.4.0
- yiisoft/yii2 *
xml yii2 module sitemap
Yii2 module for automatically generation XML Sitemap
Yii2 module for automatically generating XML Sitemap., (*1)
The preferred way to install this extension is through composer., (*2)
php composer.phar require --prefer-dist "voskobovich/yii2-sitemap-module" "*"
or add, (*3)
"voskobovich/yii2-sitemap-module" : "*"
to the require
section of your application's composer.json
file., (*4)
cache
component of your application's configuration file, for example:'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], ]
modules
section of your application's configuration file, for example:'modules' => [ 'sitemap' => [ 'class' => 'voskobovich\sitemap\Module', 'models' => [ // your models 'app\modules\news\models\News', // or configuration for creating a behavior [ 'class' => 'app\modules\news\models\News', 'config' => [ '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 ]; } ], ], ], 'urls'=> [ // your additional urls [ 'loc' => '/news/index', 'changefreq' => \voskobovich\sitemap\behaviors\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 ], ],
use voskobovich\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 ]; } ], ]; }
urlManager
of your application's configuration file, for example:'urlManager' => [ 'rules' => [ ['pattern' => 'sitemap', 'route' => 'sitemap/default/index', 'suffix' => '.xml'], ], ],
XML Sitemap, (*5)
News Sitemap, (*6)
Image sitemaps, (*7)
Yii2 module for automatically generation XML Sitemap
MIT
xml yii2 module sitemap