在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我如何与您联系?