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.

Data Model Questions /

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

Overriding the Link() method without eating my own face


Go to End


2 Posts   1341 Views

Avatar
scpi

Community Member, 21 Posts

25 April 2014 at 9:48am

Edited: 26/04/2014 4:24am

I'm trying to re-write the way a URL is constructed for a certain page type, but I'm having trouble figuring out the logic.

Say I have an address that looks like this: http://example.com/section/category/

Now, a category isn't Real Page, it's just a placeholder in the hierarchy to sort a section into smaller chunks. So the address I really want would look like http://example.com/section/#category . That would take me directly to the category part of the section page.

The problem I'm having is building the Link in a way that doesn't rely on the Link method itself. Maybe I'm not looking in the right place, but I'm having trouble piecing together exactly how to make this work. Any ideas?

Avatar
scpi

Community Member, 21 Posts

26 April 2014 at 4:10am

Edited: 26/04/2014 4:24am

Nevermind, I figured it out. I've been away from SS for too long and was going about it all wrong. This does the trick:

public function Link() {
	$link = rtrim(parent::Link(), '/');
	$link = substr_replace($link, '/#', strrpos($link, '/'), 1);
	return $link;
}