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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

SS3.1 onBeforeWrite and new Object ID


Go to End


1018 Views

Avatar
zenmonkey

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