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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Get link by ID for nested pages


4 Posts   2525 Views


16 January 2011 at 1:16pm Community Member, 197 Posts

How can I get the link of a page by its ID?

This code only works if nested URLs are disabled. It does NOT work for nested URLs:

$Link = Director::BaseURL() . DataObject::get_by_id("SiteTree", $page->ID)->URLSegment;


16 January 2011 at 3:29pm Community Member, 215 Posts

Use the Link method rather than trying to build it with the URLSegment,


$Link = DataObject::get_by_id("SiteTree", $page->ID)->Link;


16 January 2011 at 3:42pm Community Member, 197 Posts

Howard, that does not work. It does not provide a full actual link either. The URLSegment field in the SiteTree database does not contain the full url, only the URLSegment of the final child page. How can I get the FULL URL Segment as impacted by parent pages?


17 January 2011 at 1:09am Forum Moderator, 1091 Posts

$Link = DataObject::get_by_id("SiteTree", $page->ID)->Link();

should work