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.

General Questions

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

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

$DataObject::get() Question

Go to End

16 Posts   5705 Views


29 January 2010 at 3:34pm Community Member, 90 Posts

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?!


29 January 2010 at 4:36pm (Last edited: 29 January 2010 4:37pm), Forum Moderator, 5511 Posts

$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'");


9 February 2010 at 11:07am Community Member, 90 Posts

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..


9 February 2010 at 12:15pm (Last edited: 11 February 2010 3:30pm), Community Member, 243 Posts

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.


9 February 2010 at 2:36pm Community Member, 90 Posts

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..


4 February 2011 at 10:35pm Community Member, 78 Posts

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.



2 May 2013 at 1:50am Community Member, 21 Posts

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!


3 May 2013 at 9:00pm Forum Moderator, 5511 Posts

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

Go to Top