Faloude Faloude - 1 year ago 103
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.

Answer Source

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"));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download