assayer-pro/yii2-sitemap-module
Composer 安装命令:
composer require assayer-pro/yii2-sitemap-module
包简介
Yii2 module for automatically generation XML Sitemap
README 文档
README
Yii2 module for automatically generating XML Sitemap.
Installation
The preferred way to install this extension is through composer.
- Either run
php composer.phar require --prefer-dist "assayer-pro/yii2-sitemap-module" "*"
or add
"assayer-pro/yii2-sitemap-module" : "*"
to the require section of your application's composer.json file.
- Configure the
cachecomponent of your application's configuration file, for example:
'components' => [ 'cache' => [ 'class' => 'yii\caching\FileCache', ], ]
- Add a new module in
modulessection of your application's configuration file, for example:
'modules' => [ 'sitemap' => [ 'class' => 'assayerpro\sitemap\Module', ], ... ],
- Add confuguration for sitemap into components section:
'components' => [ 'robotsTxt' => [ 'class' => 'assayerpro\sitemap\RobotsTxt', 'userAgent' => [ // Disallow url for all bots '*' => [ 'Disallow' => [ ['/api/default/index'], ], 'Allow' => [ ['/api/doc/index'], ], ], // Block a specific image from Google Images 'Googlebot-Image' => [ 'Disallow' => [ // All images on your site from Google Images '/', // Files of a specific file type (for example, .gif) '/*.gif$', ], ], ], ], 'sitemap' => [ 'class' => 'assayerpro\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' => '\assayerpro\sitemap\behaviors\SitemapBehavior', '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' => \assayerpro\sitemap\Sitemap::DAILY, 'priority' => 0.8 ]; } ], ], ], ], 'urls'=> [ // your additional urls [ 'loc' => ['/news/default/index'], 'changefreq' => \assayerpro\sitemap\Sitemap::DAILY, 'priority' => 0.8, 'news' => [ 'publication' => [ 'name' => 'Example Blog', 'language' => 'en', ], '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, 'sortByPriority' => true, // default is false ], ],
- Add behavior in the AR models, for example:
use assayerpro\sitemap\behaviors\SitemapBehavior; public function behaviors() { return [ 'sitemap' => [ 'class' => SitemapBehavior::className(), /**'batchSize' => 100,*/ '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' => Sitemap::DAILY, 'priority' => 0.8 ]; } ], ]; }
- Add a new rule for
urlManagerof your application's configuration file, for example:
'urlManager' => [ 'rules' => [ ['pattern' => 'sitemap-<id:\d+>', 'route' => '/sitemap/default/index', 'suffix' => '.xml'], ['pattern' => 'sitemap', 'route' => 'sitemap/default/index', 'suffix' => '.xml'], ], ],
Console generate sitemap
Remove sitemap section from modules configuration.
Add console command configuration:
'controllerMap' => [ 'sitemap' => [ 'class' => 'assayerpro\sitemap\console\CreateController', ], ],
Add baseUrl for urlManager:
'urlManager' => [ 'baseUrl' => '', 'hostInfo' => 'http://example.com/', ],
Run command from console:
$ ./yii sitemap/create
Resources
assayer-pro/yii2-sitemap-module 适用场景与选型建议
assayer-pro/yii2-sitemap-module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.43k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2015 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xml」 「module」 「Sitemap」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 assayer-pro/yii2-sitemap-module 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 assayer-pro/yii2-sitemap-module 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 assayer-pro/yii2-sitemap-module 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony sitemap generator
PHP Simple Sitemap Generator
Interfaces for web resource models and services to retrieve and create them
Load DOM document safety
Sitemap crawler/generator. For the given URL it will return sitemap XML file with URLs and images.
Sitemap and sitemap index builder for Jigsaw.
统计信息
- 总下载量: 14.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 19
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-28