pendalf89 / yii2-sitemap
Yii2 sitemap component
Installs: 220
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-11-28 08:38:07 UTC
README
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist pendalf89/yii2-sitemap "*"
or add
"pendalf89/yii2-sitemap": "*"
to the require section of your composer.json
file.
Apply migration
yii migrate --migrationPath=vendor/pendalf89/yii2-sitemap/src/migrations
Configuration:
'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', ], ], ],
Usage
In first, create sitemap classes, for example:
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.
Yii::$app->sitemap->update();
Also, you can update one url in DB:
Yii::$app->sitemap->updateUrl('/any-url-width-date/', '2016-09-02 12:23:17');