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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

( solved ) sorting by latest ID


Go to End


3 Posts   1226 Views

Avatar
Webdoc

Community Member, 349 Posts

4 August 2015 at 6:30am

I need to add the sorting by latest ID so that i can still open the link and see the full 'Uudis' (News In estonian). But when i control the Uudis using control Uudised it will show all news and order them by id biggest id is the latest so it shows it on the top. Using SS2.4

Uudislist.php

class Uudislist_Controller extends Page_Controller
{
function show(){ 
      return array(); 
} 
    
   function Uudis(){ 
      if(isset($this->request) && $this->request->param('ID')){ 
         return DataObject::get_by_id('Uudis', (int)$this->request->param('ID')); 
      }    
   }
}

Uudis.php
function Link(){ 
		return $this->Uudislist()->Link() .'show/'.$this->ID;    
	}

Avatar
Pyromanik

Community Member, 419 Posts

4 August 2015 at 9:03pm

Edited: 04/08/2015 9:05pm

The default sort for DataObject is "Created", which is more relevant to what you want anyway (and basically equivalates to ordering by ID).
The issue is probably that Uudis seems to be a Page, which changes the default sort to "Sort" (an extra field added on SiteTree).

public static $default_sort = "Created DESC"; on Uudis class should hopefully do the trick.

Avatar
Webdoc

Community Member, 349 Posts

5 August 2015 at 3:54am

worked like a charm. :)