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.

Template Questions /

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

Get URLSegment by page ID


Go to End


3 Posts   5242 Views

Avatar
dhensby

Community Member, 253 Posts

5 September 2009 at 9:24am

Hi everyone,

I was just wondering if there is a nice clean way of getting the URLSegment (or the whole URL) for a page by parsing just the ID of the page? (i'm talking in the Page class

 not the template - but to use in the template too)

I know i can do:
DataObject::get_by_id('Page',$id)->URLSegment();

But is there a function like:

Page::getURL($id);

Any help is much appreciated.

Avatar
Willr

Forum Moderator, 5523 Posts

5 September 2009 at 11:22am

Check the SiteTree.php for any function which gets the url but I doubt it exists. A DataObject::get_by_id() function will work just as easily.

Avatar
dhensby

Community Member, 253 Posts

5 September 2009 at 11:36am

Cheers for the reply,

There only seems to be:

SiteTree::get_by_url($this->URLSegment, $idFilter)

Cheers anyway