zrk4939/yii2-sitemap

Sitemap Module

Installs: 252

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 2

Open Issues: 0

Type:yii2-extension

1.4.2 2023-11-16 13:32 UTC

This package is auto-updated.

Last update: 2024-05-16 14:42:06 UTC


README

Site Map generator module for the Yii2 framework

Installation

add

"zrk4939/yii2-sitemap": "@dev",

to the require section of your composer.json file.

and

{
    "type": "vcs",
    "url": "https://github.com/zrk4939/yii2-sitemap.git"
}

to the repositories array of your composer.json file.

Usage

console/config/main-local.php

'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'scriptUrl' => '',
            'baseUrl' => 'http://yii2.local',
        ],
    ],

main.php

'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache', // Используем хранилище yii\caching\FileCache
            'cachePath' => '@common/runtime/cache' // Храним кэш в common/runtime/cache
        ],
    ],

 'sitemap' => [
		'class' => 'zrk4939\modules\sitemap\Module',
		'storePath' => '@frontend/runtime/sitemap',
		'sitemaps' => [
			[
				'query' => ArticlesRubrics::find()->asArray(),
				'postfix' => 'types',
				'url' => function($model) {
					return \yii\helpers\Url::toRoute("/{$model['type']}");
				}
			],
			[
				'query' => Pages::find()->active()->orderBy(['id' => SORT_DESC])->limit(300),
				'postfix' => 'pages',
				'url' => function($model) {
					return \yii\helpers\Url::toRoute("/{$model['link']}");
				}
            ],
        ]
    ],

UrlManager rule

'<name:^sitemap([-0-9a-zA-Z_]+)?.xml>' => 'sitemap/default/sitemap',

console

$ php yii sitemap/console/create //создание sitemap.xml
$ php yii sitemap/console/cleaning //очиска кеш