PHP code example of devskyfly / yii-extension-sitemap

1. Go to this page and download the library: Download devskyfly/yii-extension-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/ */

    

devskyfly / yii-extension-sitemap example snippets

 
//Компонент
'sitemap' => [
    'class'=>'devskyfly\yiiExtensionSitemap\Sitemap',
    'container_init_callback'=>

'urlManager' => [
    'class' => 'yii\web\UrlManager',
    'scriptUrl' => 'http://yii-basic-test',
    'enablePrettyUrl' => true,
]

use app\models\moduleAdminPanel\contentPanel\entityWithoutSection\EntityWithoutSection;
use devskyfly\yiiExtensionSitemap\Page;
use devskyfly\yiiExtensionSitemap\PageAsset;

return $init_callback=function($container){
    /**********************************************************************/
    /** StaticPage **/
    /**********************************************************************/
    
    $pages=[
        [
            'title'=>'Index',
            'description'=>'Описание страницы',
            'keywords'=>'Ключевые слова',
            'route'=>'site/index'
        ],
    ];
    
    foreach ($pages as $page_config)
    {
        $page=new Page($page_config);
        $container->insertPage($page);
    }
    
    /**********************************************************************/
    /** DinamicPages **/
    /**********************************************************************/
    
    $pages_asserts=[
        [
            'class'=>EntityWithoutSection::class,
            'route'=>'site/index',
            
            'query_params'=>['active'=>'Y'],
            'init_callback'=>function($item){
            return [
                'title'=>$item->extensions['page']->title,
                'keywords'=>$item->extensions['page']->keywords,
                'description'=>$item->extensions['page']->description,
                'route'=>'/moduleAdminPanel/contentPanel/entity-without-section',
                'route_params'=>['entity_id'=>$item->id]
            ];
            },
            'content_callback'=>function($item){
            return $item->extensions['page']->detail_text;
            }
            ],
            ];
    
    foreach ($pages_asserts as $page_config)
    {
        $page_asset=new PageAsset($page_config);
        $container->insertPageAsset($page_asset);
    }
};

$sitemap=Yii::$app->sitemap;
$generator=$sitemap->container->getAllPages();

foreach ($generator as $page){
    $data=$page->getContent();
    BaseConsole::stdOut($page->title.PHP_EOL);
    BaseConsole::stdOut($data);
}