dev-master
9999999-devYii2 sitemap component
MIT
The Requires
by Zabolotskikh Boris
Yii2 sitemap component
The preferred way to install this extension is through composer., (*1)
Either run, (*2)
php composer.phar require --prefer-dist pendalf89/yii2-sitemap "*"
or add, (*3)
"pendalf89/yii2-sitemap": "*"
to the require section of your composer.json
file., (*4)
Apply migration, (*5)
yii migrate --migrationPath=vendor/pendalf89/yii2-sitemap/src/migrations
Configuration:, (*6)
'components' => [ 'sitemap' => [ 'class' => 'pendalf89\sitemap\Sitemap', 'sitemaps' => [ 'frontend\sitemaps\ArticlesSitemap', // see example of class below 'frontend\sitemaps\OtherSitemap', // see example of class below ], 'generator' => [ 'class' => 'pendalf89\sitemap\SitemapGenerator', 'path' => '@frontend/web', 'baseUrl' => 'https://example.com', ], ], ],
In first, create sitemap classes, for example:, (*7)
namespace frontend\sitemaps; use pendalf89\sitemap\SitemapInterface; class OtherSitemap implements SitemapInterface { /** * @inheritdoc */ public function getName() { return 'sitemap-other'; } /** * @inheritdoc */ public function getUrls() { return [ ['loc' => '/any-url/'], ['loc' => '/any-url-width-date/', 'lastmod' => '2016-09-02 12:23:17'], ]; } }
So, when you create sitemap classes, you can use component for create sitemap files., (*8)
Yii::$app->sitemap->update();
Also, you can update one url in DB:, (*9)
Yii::$app->sitemap->updateUrl('/any-url-width-date/', '2016-09-02 12:23:17');
Yii2 sitemap component
MIT