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;
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
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;
Use the Link method rather than trying to build it with the URLSegment,
try:
$Link = DataObject::get_by_id("SiteTree", $page->ID)->Link;
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?
$Link = DataObject::get_by_id("SiteTree", $page->ID)->Link();
should work