40katty04/cakephp-sitemap
Composer 安装命令:
composer require 40katty04/cakephp-sitemap
包简介
Sitemap Generator plugin for CakePHP 4.x apps
README 文档
README
Sitemap generator plugin for CakePHP 4.1 apps
Installation
This package is available for easy installation through Packagist
composer require 40katty04/cakephp-sitemap "~2.0"
Then make sure to load the plugin normally in your app. e.g.
# somewhere in config/bootstrap.php Plugin::load('Sitemap', [ 'routes' => true, ]);
Finally, set your configuration array (see below)
Configuration
The plugin will look for an array of info using Configure::read('Sitemap') so just make sure such an array is loaded during bootstrapping. The easiest way to do this is to add it to your config/app.php file.
There are two sections the plugin looks for static pages and dynamic pages.
Static Pages
Static pages are nested under Sitemap.static which expects an array of URLs. This can take any URL accepted by Router::url().
'Sitemap' => 'static' => ['_name' => 'pages:about'], 'http://example.com/search', ['controller'=>'Pages', 'action'=>'display', 'terms-of-service'],
Dynamic Pages
You can dynamically create links by nesting a group of config settings under Sitemap.dynamic
'Sitemap' => 'dynamic' => 'Items' => #the name of the model to get entities for 'cachekey' => 'sitemap', # cachekey to use (e.g. from Configure::read('Cache.sitemap')) 'finders' => [ .. ], # array of model-layer finders for getting entities 'xmlTags' => # xml tags to output with each sitemap line 'loc' => 'url' # default 'url'; entity attribute name, or array, or string 'priority' => 0.5 # default 0.5; 0 to 1 priority 'lastmod' => 'updated' # default 'updated'; entity attribute giving lastmod time 'changefreq' => 'daily' # default 'daily'; always, hourly, daily, weekly, yearly, never
Example Configuration
Here's a sample configuration straight from one of the projects using this plugin
# .. in config/app.php ..., 'Sitemap' => [ 'static' => [ ['_name' => 'user-register'], ['_name' => 'user-resetpw'], ['_name' => 'user-login'], ['_name' => 'user-logout'], ['_name' => 'user-dashboard'], ['_name' => 'privacy'], ["_name" => "contact-us"], ["_name" => "rewards"], ["_name" => "terms-of-service"], ["_name" => "about-us"], ["_name" => "search"], ], 'dynamic' => [ 'Categories' => [ 'cacheKey' => 'sitemap', 'finders' => [ 'all' => [ 'condition' => [ 'Categories.enabled' => true ] ], ], 'xmlTags'=> [ 'loc' => 'permalink', 'priority' => '0.9', 'changefreq' => 'always', ], ], 'Products' => [ 'cacheKey' => 'sitemap', 'finders' => [ 'all' => [ 'condition' => [ 'Products.enabled' => 'true', function ($exp) { return $exp->notIn('Products.status', [ 'Stalled', 'Placed', 'Lost to Competition', 'Filled by Client', 'Cancelled' ]); } ], ], ], 'xmlTags'=> [ 'loc' => [ 'urlBody' => '/product', 'queryParams' => ['productId' => 'id'] // queryParam => CollumnNameInDb ], 'priority' => '0.9', 'changefreq' => 'always', ], ], ], ],
which produces the following
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> <url> <loc>http://example.com/</loc> <changefreq>always</changefreq> <priority>1.0</priority> </url> <url> <loc>http://example.com/register</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/reset-password</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/login</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/logout</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/my-account</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/privacy</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/contact-us</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/rewards</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/terms-of-service</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/about-us</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/search/</loc> <priority>0.5</priority> <changefreq>weekly</changefreq> </url> <url> <loc>http://example.com/product/spice-widgets</loc> <priority>0.9</priority> <changefreq>always</changefreq> </url> <url> <loc>http://example.com/product/posh-widgets</loc> <priority>0.9</priority> <changefreq>always</changefreq> </url> <url> <loc>http://example.com/product?productId=45673</loc> <priority>0.9</priority> <changefreq>always</changefreq> </url> <url> <loc>http://example.com/product?productId=89654</loc> <priority>0.9</priority> <changefreq>always</changefreq> </url> </urlset>
40katty04/cakephp-sitemap 适用场景与选型建议
40katty04/cakephp-sitemap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 84 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 40katty04/cakephp-sitemap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 40katty04/cakephp-sitemap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 84
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-04-19