21281 Posts in 5729 Topics by 2600 members
| Go to End | Next > | |
| Author | Topic: | 2049 Views |
-
$DataObject::get() Question

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?!
Thanks -
Re: $DataObject::get() Question

29 January 2010 at 4:36pm Last edited: 29 January 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'");
... -
Re: $DataObject::get() Question

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$filter="ListingType='Business'";
$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..
-
Re: $DataObject::get() Question

9 February 2010 at 12:15pm Last edited: 11 February 2010 3:30pm
Hi, you seem to have the wrong end of the stick with the DataObject::get() method.
Have a look at this: http://doc.silverstripe.org/doku.php?id=datamodel#querying_data
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.
-
Re: $DataObject::get() Question

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..
-
Re: $DataObject::get() Question

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 HomePage.ss i use
<% control GetPageList %>
$Title
<% end_control %>But i see only one results.
Could you please show the trick.
Bunheng
-
Re: $DataObject::get() Question

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()
->sort($order)
->where('"BookstoreBook"."Title" LIKE $searchString');
return $entries ? $entries : false;How can I use "LIKE" in the where function?????
Thank you Please help! -
Re: $DataObject::get() Question

3 May 2013 at 9:00pm
$entries = BookstoreBook::get()
->where("Title LIKE '$searchString'")
->sort($order);
| 2049 Views | ||
| Go to Top | Next > |




