https://github.com/itstructure/yii2-sitemap-generator
https://github.com/itstructure/yii2-sitemap-generator
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/itstructure/yii2-sitemap-generator
- Owner: itstructure
- License: gpl-2.0
- Created: 2020-07-06T08:03:26.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-06T08:04:39.000Z (almost 6 years ago)
- Last Synced: 2025-03-11T10:07:14.964Z (about 1 year ago)
- Language: PHP
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
yii2-sitemap-generator
===================
Yii2 component for generation sitemap.xml
It is reworked package, based on [Dreamjobs yii2 sitemap generator](https://github.com/dreamjobs/yii2-sitemap-generator)
Installation
------------
Run command
`composer require itstructure/yii2-sitemap-generator "~1.0.0"`
Configuration
-------------
Set in `"./console/config/main.php"`
```php
return [
'controllerMap' => [
'sitemap' => [
'class' => 'Itstructure\Sitemap\SitemapController',
'baseUrl' => 'https://example.com',
'modelsPath' => '@console/models/sitemap', // Sitemap-data models directory
'modelsNamespace' => 'console\models\sitemap', // Namespace in [[modelsPath]] files
'savePathAlias' => '@frontend/web', // Where would be placed the generated sitemap-files
'sitemapFileName' => 'sitemap.xml', // Name of main sitemap-file in [[savePathAlias]] directory
],
],
];
```
Set in `"./environments/prod/console/config/main-local.php"`
```php
'components' => [
// fix console create url
'urlManager' => [
'baseUrl' => 'http://example.com',
],
],
```
Set in `"./environments/dev/console/config/main-local.php"`
```php
'components' => [
// fix console create url
'urlManager' => [
'baseUrl' => 'http://example.local',
],
],
```
Run command
```code
php ./init
```
OR just apply same config to your "/console/config/main-local.php"
ALSO you can merge urlManager rules from frontend(or common) to console config.
Just change "/console/config/main.php" file:
```php
// get config of urlManager from frontend for correctly create urls in console app
$frontend = require(__DIR__ . '/../../frontend/config/main.php');
$frontendUrlManager = [
'components' => [
'urlManager' => $frontend['components']['urlManager'],
],
];
// ...
// Merge frontend urlManager config with console application main config
return yii\helpers\ArrayHelper::merge($frontendUrlManager, [
'id' => 'app-console',
// ...
];
```
Also useful append .gitignore for ignore all generated sitemaps files:
```code
# sitemaps
/frontend/web/sitemap*.xml
```
TBD: creating sitemap-data models
Usage
-----
Run Yii console command in project root:
```code
php ./yii sitemap
```