alexs/yii2-sitemap

Sitemap for Yii2 Framework.

Installs: 34

Dependents: 0

Suggesters: 0

Security: 0

Type:yii2-extension

1.1.5-stable 2017-09-20 08:12 UTC

This package is auto-updated.

Last update: 2024-10-25 13:19:20 UTC


README

Sitemap extension for Yii2

Rules

You'll need to create your sitemap, for example:

<?php
namespace app\components;
use alexs\yii2sitemap\BaseSitemap;
use yii\helpers\Url;

class Sitemap extends BaseSitemap
{
    public function getUrls() {
        $domain = 'http://examplesite.com';
        $static_urls = [
            $domain,
            $domain . '/article',
            $domain . '/another-article',
        ];
        $dynamic_urls = [];
        $dynamic_urls[] = Url::to(['/url/to'], true);
        return array_merge($static_urls, $dynamic_urls);
    }
}

And controller:

<?php
namespace app\controllers;
use app\components\Sitemap;
use yii\web\controller;

class SitemapController extends Controller
{
    public function actions() {
        return [
            'generate'=>[
                'class'=>'alexs\yii2sitemap\GenerateAction',
                'SitemapClass'=>new Sitemap,
            ],
        ];
    }
}

You can follow the url