Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

SS3.1 onBeforeWrite and new Object ID

Go to End



Community Member, 545 Posts

12 November 2013 at 7:55am

Now that in 3.1 a new dataobject is given a temporary ID, I'm wondering how to do an onBeforeWrite check to craete a new folder. I had been using.

if($this->ID != 0 && $this->FolderID == 0) {
			$filter = URLSegmentFilter::create();
			$folderName = $filter->filter($this->Title);
			$folderExists = Folder::find_or_make('Products/'.$folderName.'/');
			$this->FolderID = $folderExists->ID;

But now since it's craeting an Object called New Object it creates one folder called new-object then matchas all subsequent new items to it. I'm using if($this->Title 1= "New Product") but that just seems like its going to be called on every save