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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

$DataObject::get() Question

Go to End

16 Posts   17087 Views


Community Member, 90 Posts

29 January 2010 at 3:34pm

Hey,geeks. I met a problem try to select the useful information i want from the database.
I am using $DataObject::get("ListingPage",$filter)

Whats the right format to provide $filter here?! i wannto use the where statement: "where ListingPage.ListingType=Business"..
But not sure how to put them in the function()..

any suggestions?!


Forum Moderator, 5523 Posts

29 January 2010 at 4:36pm

Edited: 29/01/2010 4:37pm

$filter is basically just added into the SQL WHERE statement. So the format is standard sql without the 'WHERE'. For example

DataObject::get('ListingPage', "ListingType = 'Business'");

You can combine more then 1 command in the filter... eg

DataObject::get('ListingPage',"ListingType = 'Something' AND AnotherColumn = '2'");


Community Member, 90 Posts

9 February 2010 at 11:07am

I encountered a problem with Dataobject again.
I want to grab a sortted dataset (byListingDate DESC) from database frist.
can do it by using:
$listings=DataObject::get("ListingPage","","ListingDate DESC");

Then select the ListingPage items by different Categories.
So i did


$records= DataObject::get($listings,$filter);

return $records;

i assume it should give me the result i want, because the $listings should also be a "ListingPage" Type object and as well as the "$records". But seems the result is a little bit strange..

Donot know whats the good way to handle the twice DB queries. anysuggestions will be appreciated..


Community Member, 253 Posts

9 February 2010 at 12:15pm

Edited: 11/02/2010 3:30pm

Hi, you seem to have the wrong end of the stick with the DataObject::get() method.

Have a look at this:

Simply, you define you DataObject class, filter, sort order, join and limit all in one function (but seperate parameters, of course). All the parameters take strings and all are optional except the first parameter.

So what you want to do, seems to be:

DataObject::get('ListingPage','ListingType = "Business"','ListingDate DESC');

Thus getting all the listing pages where column 'ListingType' is 'Business' and then sorted by ListingDate with newest at the top.

Hope that clears that up.


Community Member, 90 Posts

9 February 2010 at 2:36pm

Hey.thx, Pigeon.

I was totally wrong about the things i am archiving.

Originally, i think it could be helpful, we can sort of the listing pages by date desc then the lastest come up first. and we can sort of the lastest items by different categories.. But acutally its stupid..

Its better to do DataObject::get("ListingPage",$fitler,"ListingDate DESC");

Thanks for ur suggestion and answer for my stupid logical problem..


Community Member, 78 Posts

4 February 2011 at 10:35pm

Good morning from Cambodia

I did the following code for to get pages display on my home page

class HomePage_Controller extends Page_Controller {
function GetPageList(){
$PageList = DataObject::get("Page", "ShowOnFrontPage=1", "LastEdited DESC", "", 4);
return $PageList;

inside i use

<% control GetPageList %>
<% end_control %>

But i see only one results.

Could you please show the trick.



Community Member, 24 Posts

2 May 2013 at 1:50am

Hi all!!

I am trying to make this query in silverstripe but it doesn't want to work:

$entries = BookstoreBook::get()
->where('"BookstoreBook"."Title" LIKE $searchString');
return $entries ? $entries : false;

How can I use "LIKE" in the where function?????
Thank you Please help!


Forum Moderator, 5523 Posts

3 May 2013 at 9:00pm

$entries = BookstoreBook::get()
->where("Title LIKE '$searchString'")

Go to Top