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

[SOLVED] URL slug instead of ID on DataObject?


Go to End


11 Posts   11791 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