Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SilverStripe管理员中强制保存小写URL_Silverstripe - Fatal编程技术网

在SilverStripe管理员中强制保存小写URL

在SilverStripe管理员中强制保存小写URL,silverstripe,Silverstripe,为了搜索引擎优化的目的,我需要确保所有的网址保存为小写 即使用户以大写形式键入永久链接,我如何强制SilverStripe管理员以小写形式保存URL?您可以在页面的onbeforewite方法中执行此操作: protected function onBeforeWrite() { parent::onBeforeWrite(); //this is important! $this->URLSegment = strtolower($this->URLSegment)

为了搜索引擎优化的目的,我需要确保所有的网址保存为小写


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

您可以在
页面的
onbeforewite
方法中执行此操作:

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

请参见

Thank works perfect,它必须添加到:class Page extends SiteTree{}函数中。当然,如果您希望它更加模块化和可移植,可以将它放在DataExtension中(其中还有onBeforeWrite()方法)。@wmk我如何与您联系?