3067 Posts in 867 Topics by 649 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 831 Views |
-
Sorting the dataobjects fetched

17 February 2011 at 3:27pm
So I know you can change the sorting in DataObject::get but I'm wondering if it's possible to accomplish the same result from the template without having to build a function in the controller that fetches the objects via DataObject::get with sorting parameters defined.
I'm just mainly looking to eliminate that extra step. The default behavior is to list the objects with oldest first, newest last, and that needs to be reversed for a particular instance.
-
Re: Sorting the dataobjects fetched

18 February 2011 at 12:53am
something like this...
http://www.silverstripe.org/general-questions/show/15690?start=8#post298878
(with an extra param for sort)
? -
Re: Sorting the dataobjects fetched

18 February 2011 at 7:43am
Well.. not really, that's pretty much the same thing. Like I said, I was just mainly looking to eliminate the extra step of having to build a function somewhere for this.
You know how images can be resized using $Image.SetHeight, .SetWidth, etc? Something like that, like $Object.Sort(created, desc).
Either way, looks like the only way is to do it like the example you showed me or this:
function CustomObject() {
return DataObject::get('CustomObject', '', 'Created DESC');
} -
Re: Sorting the dataobjects fetched

18 February 2011 at 12:00pm
fair enough - I thought the post would be extremely flexible - you only one function, that you could then call from the template like this... In fact, I'm going to test it in my code for simple cases.
<% control GetStuff(MyDataObject,Description LIKE '%test%',Name ASC) %>
How about this, with php;s late binding maybe the following would work?
<% control Sort(MethodName,FieldName,ASC) %>
//--
function Sort($strMethodName,$strSortFeild,$strSortDirection) {
$dos = $this->$strMethodName;
$dos->sort($strSortFeild,$strSortDirection);
return $dos;
}
| 831 Views | ||
|
Page:
1
|
Go to Top |


