我添加URLSegments到數據對象(產品)所以後來我可以顯示產品名稱爲URL ....代碼工作正常:Silverstripe批量保存所有數據對象
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手動保存每個產品?