Jump to:

3448 Posts in 1062 Topics by 738 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Sort field in SiteTree object

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

Page: 1
Go to End
Author Topic: 392 Views
  • jaaf
    Avatar
    Community Member
    24 Posts

    Sort field in SiteTree object Link to this post

    Hi,

    I would like to use the method described in a thread on the forums
    at http://www.silverstripe.org/customising-the-cms/show/6320?start=8#ForumContent
    Here is a partial reproduction of the conclusive post in this thread:

    cbolt's solution worked well for me. I made two minor edits...

    PreviousPage function would fail if Children return a dataobjectset with no children. So updated the function to use Count():

    function PreviousPage() {
    $where = "ParentID = {$this->ParentID} AND Sort < {$this->Sort}";
    $pages = DataObject::get("SiteTree", $where, "Sort DESC", "", 1);
    if($pages) {
    foreach($pages as $page) {
    // if page has a child go to the last child page
    $children = $page->AllChildren();
    if ($children->Count()) {
    foreach ($children as $child) {
    continue;
    }
    return $child;
    }
    return $page;
    }
    }

    Though being a beginner with SilverStripe and a rather non experienced programmer in php/msyql , my general rule of conduct is trying to understand what I am applying when coming from other more experienced people.

    The trouble I have here is in understanding what the Sort field in the SiteTree database columns means. I can see, having a look at this field in the database that it may have various numerical value.
    Where can I find an explanation of how to interpret these values ?
    Many thanks in advance:

  • jaaf
    Avatar
    Community Member
    24 Posts

    Re: Sort field in SiteTree object Link to this post

    Hi.
    I have not found any explanation but it seems that the value of the Sort fields is the order in which a SiteTree appears for a given level of hierarchy
    It restarts at 1 at each level in the tree for SiteTrees that have a common parent.
    I hope I am right.

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Sort field in SiteTree object Link to this post

    Yes the sort value is level specific. It is generated automatically by SilverStripe when you create a page and altered whenever you reorder the pages in the sitetree.

    From your code sample it sounds like it's trying to get the previous page. The previous page is the one which has the next lowest sort after the current page (say 1, 3, 6, 8 and you're on page 6 the previous page would be 3).

  • jaaf
    Avatar
    Community Member
    24 Posts

    Re: Sort field in SiteTree object Link to this post

    Thank you Willr,

    That's clear to me now.
    I go on enjoying SilverStripe.

    392 Views
Page: 1
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.