Faloude Faloude - 6 months ago 42
PHP Question

SilverStripe return URLSegment from SiteTree relation

So I have this:

private static $has_one = array(
'ButtonLink' => 'SiteTree'

and this field

$fields->addFieldToTab('Root.Main', TreeDropdownField::create("ButtonLink", "Page link", "SiteTree"));

So that users can link this DataObject to a page from SiteTree. On the front-end I'm trying to return the


But it doesn't return anything.


Found it. You need to append ID to the field identifier because that's the db column name where the foreign record reference key is saved (SiteTree).

$fields->addFieldToTab('Root.Main', TreeDropdownField::create("ButtonLinkID", "Page link", "SiteTree"));