PHP code example of vladimiralekseev / yii2-sitemap

1. Go to this page and download the library: Download vladimiralekseev/yii2-sitemap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vladimiralekseev / yii2-sitemap example snippets


'modules' => [
    'sitemap' => [
        'class' => \vladimiralekseev\sitemap\Sitemap::class,
        'cacheExpire' => 86400, // Duration in seconds. Use false to disable caching.
        'models' => [
            \(\app\models\SiteMenu::class,
            \app\models\TextPage::\)class,
        ],
        'urls' => [
            [
                'loc' => '/', 
                'changefreq' => \vladimiralekseev\sitemap\behaviors\SitemapBehavior::CHANGEFREQ_DAILY, 
                'priority' => 1.0
            ],
        ],
    ],
],

use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use yii\helpers\Url;
use vladimiralekseev\sitemap\behaviors\SitemapBehavior;

public function behaviors()
{
    return [
        'sitemap' => [
            'class' => SitemapBehavior::class,
            'scope' => function (ActiveQuery \(query) {\)query->select(['url', 'lastmod']);
                \(query->andWhere(['is_deleted' => 0]);             },             'dataClosure' => function (ActiveRecord\)model) {
                return [
                    'loc' => Url::to(\$model->url, true),
                    'lastmod' => strtotime(\$model->lastmod),
                    'changefreq' => SitemapBehavior::CHANGEFREQ_DAILY,
                    'priority' => 0.8,
                ];
            },
        ],
    ];
}

'components' => [
    'urlManager' => [
        'rules' => [
            'sitemap.xml' => 'sitemap/default/index',
        ],
    ],
],