Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Hierarchical / Semantic URLs

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

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

Page: 1 2
Go to End
Author Topic: 3870 Views
  • ByteMe
    Avatar
    Community Member
    1 Post

    Hierarchical / Semantic URLs Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Hierarchical / Semantic URLs Link to this post

    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!

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Hierarchical / Semantic URLs Link to this post

    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.

  • KatB
    Avatar
    Community Member
    94 Posts

    Re: Hierarchical / Semantic URLs Link to this post

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

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: Hierarchical / Semantic URLs Link to this post

    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.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Hierarchical / Semantic URLs Link to this post

    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

  • KatB
    Avatar
    Community Member
    94 Posts

    Re: Hierarchical / Semantic URLs Link to this post

    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.

  • dospuntocero
    Avatar
    Community Member
    54 Posts

    Re: Hierarchical / Semantic URLs Link to this post

    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!

    3870 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.