【问题标题】:Force saving a lowercase URL in the SilverStripe admin在 SilverStripe 管理员中强制保存小写 URL
【发布时间】:2016-01-23 07:00:54
【问题描述】:

出于 SEO 目的,我需要确保所有 URL 都保存为小写。

即使用户键入大写的永久链接,我如何强制 SilverStripe 管理员以小写形式保存 URL?

【问题讨论】:

    标签: silverstripe


    【解决方案1】:

    您可以在 PageonBeforeWrite 方法中执行此操作:

    protected function onBeforeWrite() {
        parent::onBeforeWrite(); //this is important!
        $this->URLSegment = strtolower($this->URLSegment);
    }
    

    API docs

    【讨论】:

    • 感谢完美,必须添加到:class Page extends SiteTree {} 函数中。
    • 当然你可以把它放在一个 DataExtension 中(你也有 onBeforeWrite() 方法)如果你更喜欢模块化和便携。
    • @wmk 怎么联系你?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-16
    • 1970-01-01
    • 2011-04-09
    • 2011-06-02
    • 1970-01-01
    相关资源
    最近更新 更多