innoweb / silverstripe-remove-trailing-slash
此包已被弃用且不再维护。未建议替代包。
从页面链接中删除尾部斜杠。
1.0.1
2022-05-10 03:59 UTC
Requires
- silverstripe/cms: ^4.1
- silverstripe/vendor-plugin: ^1.0
This package is auto-updated.
Last update: 2023-04-16 00:30:44 UTC
README
概述
从页面链接中删除尾部斜杠。
SiteTree 是 Silverstripe 中唯一一个向链接添加尾部斜杠的类。此模块将其清理。
需求
- Silverstripe CMS 4.x
此模块的更改已合并到 Silverstripe 5 的核心中,请参阅 2780。
安装
使用 composer 安装模块
composer require innoweb/silverstripe-remove-trailing-slash dev-master
然后运行 dev/build。
配置
遗憾的是,SiteTree::RelativeLink()
包含一个问题,其中基本链接和动作通过强制 /
连接。当没有动作可用时,这会在后面留下尾部斜杠。
因为扩展点 updateRelativeLink
在连接之前调用,所以你需要使用以下代码重写 Page::RelativeLink()
/**
* Remove trailing slash from page links. SiteTree forces a trailing slash if no action is set, which doesn't
* make sense, really. Every other functionality in SS doesn't add the trailing slash, e.g. in HTTP and
* HTTPRequest classes.
*
* @see \SilverStripe\CMS\Model\SiteTree::RelativeLink()
*/
public function RelativeLink($action = null)
{
$link = parent::RelativeLink($action);
$link = rtrim($link, '/');
return $link;
}
有关此问题的详细信息,请参阅 pull request 2677。
许可证
BSD 3-Clause License,请参阅 许可证