php - yii2: working with yii2-sitemap-module -


i used https://github.com/himiklab/yii2-sitemap-module in yii2 project

this console :

return [     'id' => 'basic-console',     'language' => 'fa-ir',     'basepath' => dirname(__dir__),     'bootstrap' => ['log', 'gii'],     'controllernamespace' => 'app\commands',     'modules' => [         'gii' => 'yii\gii\module',         'user' => [             'class' => 'dektrium\user\module',             'sourcelanguage' => 'en-us',             'languages' => 'fa-ir'         ],         'sitemap' => [             'class' => 'himiklab\sitemap\sitemap',             'models' => [                 // models                 'app\modules\news\models\news',                 // or configuration creating behavior                 [                     'class' => 'app\modules\news\models\news',                     'behaviors' => [                         'sitemap' => [                             'class' => sitemapbehavior::classname(),                             'scope' => function ($model) {                         /** @var \yii\db\activequery $model */                         $model->select(['url', 'lastmod']);                         $model->andwhere(['is_deleted' => 0]);                     },                             'dataclosure' => function ($model) {                         /** @var self $model */                         return [                             'loc' => url::to($model->url, true),                             'lastmod' => strtotime($model->lastmod),                             'changefreq' => sitemapbehavior::changefreq_daily,                             'priority' => 0.8                         ];                     }                         ],                     ],                 ],             ],             'urls' => [                 // additional urls                 [                     'loc' => '/news/all',                     'changefreq' => \himiklab\sitemap\behaviors\sitemapbehavior::changefreq_daily,                     'priority' => 0.8,                     'news' => [                         'publication' => [                             'name' => 'example blog',                             'language' => 'fa',                         ],                         'access' => 'subscription',                         'genres' => 'blog, usergenerated',                         'publication_date' => 'yyyy-mm-ddthh:mm:sstzd',                         'title' => 'example title',                         'keywords' => 'example, keywords, comma-separated',                         'stock_tickers' => 'nasdaq:a, nasdaq:b',                     ],                     'images' => [                         [                             'loc' => 'http://example.com/image.jpg',                             'caption' => 'this example of caption of image',                             'geo_location' => 'city, state',                             'title' => 'example image',                             'license' => 'http://example.com/license',                         ],                     ],                 ],             ],             'enablegzip' => true, // default false             'cacheexpire' => 1, // 1 second. default 24 hours         ],     ],     'components' => [         'cache' => [             'class' => 'yii\caching\filecache',         ],         'log' => [             'targets' => [                 [                     'class' => 'yii\log\filetarget',                     'levels' => ['error', 'warning'],                 ],             ],         ],         'db' => $db,     ],     'params' => $params, ]; 

this web.php:

  'urlmanager' => [             'enableprettyurl' => true,             'showscriptname' => true,             'enablestrictparsing' => false,             'rules' => [                 ['pattern' => 'sitemap', 'route' => 'sitemap/default/index', 'suffix' => '.xml'],             // ...             ],         ],         'request' => [             // !!! insert secret key in following (if empty) - required cookie validation             'cookievalidationkey' => 'salt',         ],         'cache' => [             'class' => 'yii\caching\filecache',         ], 

this news controller :

use himiklab\sitemap\behaviors\sitemapbehavior;       public function behaviors() {         return [              'sitemap' => [                 'class' => sitemapbehavior::classname(),                 'scope' => function ($model) {             /** @var \yii\db\activequery $model */             $model->select(['id']); //            $model->andwhere(['is_deleted' => 0]);         },                 'dataclosure' => function ($model) {             /** @var self $model */             return [                 'loc' => url::to($model->url, true),                 'lastmod' => strtotime($model->lastmod),                 'changefreq' => sitemapbehavior::changefreq_daily,                 'priority' => 0.8             ];         }             ],             'verbs' => [                 'class' => verbfilter::classname(),                 'actions' => [                     'delete' => ['get'],                 ],             ],         ];     } 

where xml file(url)?? change should in code?

if controller (sitemap/default/index) work well.

your sitemap must created in root directory via sitemap.xml file name, , accessible http://your-domain/sitemap.xml url.

for change refer code:

    'rules' => [         ['pattern' => 'sitemap', 'route' => 'sitemap/default/index', 'suffix' => '.xml'],     ], 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -