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.

Data Model Questions /

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

[SOLVED] URL slug instead of ID on DataObject?


Go to End
Reply


11 Posts   8015 Views

Avatar
LesC

Community Member, 70 Posts

10 December 2009 at 9:49pm

Hi Potion Maker,

I should have marked this one as resolved - Martijn's solution worked perfectly.

I'm not sure how you would get it working with yours, but I'd try generating a string from the two components, then sticking them thru the generateURLSegment function.

Les

Avatar
Judge

Community Member, 79 Posts

6 March 2010 at 3:09am

Nice. So SiteTree::generateURLSegment() is SilverStripe's slug generation equivalent.

-- Jason

Avatar
neilcreagh

Community Member, 136 Posts

8 March 2017 at 3:50am

I think it should be SiteTree::create()->
eg.

public function onBeforeWrite () {
		parent::onBeforeWrite ();
		if($this->Title) { $this->Fieldname = SiteTree::create()->generateURLSegment($this->Title); }
	}
 

Go to Top