我已将 URLSegments 添加到 DataObjects(产品),因此我可以将 ProductName 显示为 URL ....代码工作正常:
public function onBeforeWrite(){
if($this->Name){
$this->URLSegment = SiteTree::GenerateURLSegment($this->Name);
if($object = DataObject::get_one($this->ClassName, "URLSegment='".$this->URLSegment."' AND ID !=".$this->ID)){
$this->URLSegment = $this->URLSegment.'-'.$this->ID;
}
} else {
$this->URLSegment = SiteTree::GenerateURLSegment($this->ClassName.'-'.$this->ID);
}
parent::onBeforeWrite();
}
但是,我有超过 1000 个产品...有没有办法为代码中的所有产品数据对象生成批量保存(即一次性),所以我不必通过 CMS 手动保存每个?