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.

Archive /

Our old forums are still available as a read-only archive.

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

Hierarchical / Semantic URLs


Go to End


9 Posts   4690 Views

Avatar
ByteMe

Community Member, 1 Post

17 November 2007 at 9:45pm

I have recently discovered Silverstripe and love it, especially how uncomplicated it is. However, at this point in time, I won't be using it due to what I consider a glaring oversight - the inability to have hierarchical / semantic URLs.

e.g. domain.com/category/subcategory

I'm sure I don't need to go in to how important hierarchical / semantic URLs are, especially for user experience (remembering a URL, knowing where you are in a site) and for SEO, however I will express my surprise and disappointment at the lack of support.

I'm sure the developers will be able to justify why they don't support hierarchical / semantic URLs but rather than hiding behind some technical reason I encourage you to take a positive view and look to overcome any of the challenges and to address this issue.

Given how important hierarchical / semantic URLs are, I'm sure that I'm not the only one that would be seeking such functionality nor the only one not using Silverstripe specifically for this reason.

Keep up the good work.

Avatar
Willr

Forum Moderator, 5523 Posts

18 November 2007 at 12:01am

You arent the only one making this request! This request has been brought up many many times and you might like to look at http://www.silverstripe.com/extending-hacking-silverstripe-forum/flat/526. Sams post on the second page sums up pretty well.

And It does make larger sites harder to handle without hierarchical URL eg knowing where you are on the site but really this can be offset some way by good navigation structure (showing current and section styles Thats why we have $LinkingMode) and breadcrumbs.

As more users are likely or just as likely to click/visual on page cues to get where they want rather then edit/look at the url. Its the best you can do at the moment till whenever multi level URL structures become reality!

Avatar
dio5

Community Member, 501 Posts

18 November 2007 at 9:19am

Actually I'm really starting to love how SS handles it: URLSegment/Action/ID or specified otherwise.

In that way it is possible to do something like category/subcategory/name. You just have to make specific methods on your controller. Semantic urls is something that you completely control yourself in this way.

Avatar
KatB

Community Member, 105 Posts

25 January 2008 at 3:38pm

dio5, could you please post an example of what you mean, with the controller?
Thanks!

Avatar
Liam

Community Member, 470 Posts

26 January 2008 at 4:55am

Yes, I would love to see an example.

I just posted a topic last night with a few questions, and this was one of them.

I've read the reasoning behind it, and don't expect it built into the core any time soon, but this would be a feature I'd _love_ to have.

Avatar
Sean

Forum Moderator, 922 Posts

27 January 2008 at 1:31pm

Edited: 27/01/2008 1:36pm

It's actually relatively simple.

As an example, we have a URL like http://mysite.com/home/show/5 - semantically this means we want we might want to show the content for this page from the page ID 5, instead of the current page content.

We can do something like this, on our controller class:

function show() {
	$params = Director::urlParams();
	
	if($params['ID'] && is_numeric($params['ID'])) {
		$page = DataObject::get_by_id('Page', (int)$params['ID']);
		if($page) {
			return array(
				'Content' => $page->Content
			);
		}
	}
	
	Director::redirect($this->Link() . 'show/' . $this->ID);
}

The above example is extremely simple. All it does is swap the Content field on this page with a different one, based on the ID given in the URL. So, if you go to http://mysite.com/home/show/10 it will show the Content field from page ID 10. If you just go to http://mysite.com/home/show without the ID, then it redirects to the show action with the current page ID.

As you can see, it's pretty flexible, so you can implement methods like show() edit() and delete() on your web apps, for example.

Hope this helps!

Cheers,
Sean

Avatar
KatB

Community Member, 105 Posts

29 January 2008 at 1:59pm

I am still working through this, but I think each step should be explained.

$Director::urlParams() returns an array with the following:

URLSegment=>
Action=>
ID=>
OtherID=>

As far as I can tell, a URI such as http://www.domain.com/artists/show/5/2 gets translated into

URLSegment=>artists
Action=>show
ID=>5
OtherID=>2

This is meant for web apps whereby you can control functions from the URI. So it calls up the content for 'Artists', looks for a function called 'show' and sends it the parameters, '5' and '2'.

However, I am still working through how this can help with http://www.domain.com/category/subcategory.html. It appears from first glance that translating between the two may get ugly as it is does not appear to be meant to translate legacy URI schemas.

Please correct me if my understanding is incorrect.

Avatar
dospuntocero

Community Member, 54 Posts

17 July 2008 at 10:20am

maybe you can use this: http://sstest.grayzagdesign.com/nested-url-s/

i have been talking with some of the best guys in the irc channel and gave me this patch to make hierachical semantic urls to work!

Go to Top