2

yii2 プロジェクトでhttps://github.com/himiklab/yii2-sitemap-moduleを使用しました

これは私のコンソールです:

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' => [
                // your models
                'app\modules\news\models\News',
                // or configuration for creating a 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' => [
                // your 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 is an example of a caption of an image',
                            'geo_location' => 'City, State',
                            'title' => 'Example image',
                            'license' => 'http://example.com/license',
                        ],
                    ],
                ],
            ],
            'enableGzip' => true, // default is false
            'cacheExpire' => 1, // 1 second. Default is 24 hours
        ],
    ],
    'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
    ],
    'params' => $params,
];

これは私のweb.phpです:

  'urlManager' => [
            'enablePrettyUrl' => TRUE,
            'showScriptName' => TRUE,
            'enableStrictParsing' => FALSE,
            'rules' => [
                ['pattern' => 'sitemap', 'route' => 'sitemap/default/index', 'suffix' => '.xml'],
            // ...
            ],
        ],
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'salt',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],

これは私のニュースコントローラーです:

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'],
                ],
            ],
        ];
    }

私のxmlファイル(URL)はどこですか?? コードでどのような変更を行う必要がありますか?

4

2 に答える 2