21308 Posts in 5737 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1102 Views |
-
Get DataObejctSet of pages with ID filter

5 September 2009 at 9:35am
Hello Experts,
I need help!
I want a DataObejctSet consisting of a specific type of pages, filtered by their id.
In other words, i want the query to return 3 pages, all of the type "WithPreviewPage", identified by their id.The pages are of the type "WithPreviewPage" and are not necessarily children of the same page.
The below code will give me all of the pages of type "WithPreviewPage", but i don't know how to filter by ID's.
I can do DataObject::get("WithPreviewPage", "Sort = 3"); which will give me the record with the sort order 3, but as soon as i attempt to use ID i get an "Website error", no further description.class ForsidePage_Controller extends Page_Controller {
function showPreviews() {
$records = DataObject::get("WithPreviewPage");//, $filter, $sort, $join, $limit);
print "<pre>";
print_r($records);
print "</pre>";
return ($records);
}
}Can anyone please show me how to return the 3 pages of WithPreviewPage with the id's 8,9,10.
Thank you for your time.
-
Re: Get DataObejctSet of pages with ID filter

5 September 2009 at 11:25am
"Website error", no further description.
Put the site into dev mode so you can see the full error messages. Add Director::set_environment_type("dev"); to your _config file or add ?isDev=1 to the url.
Try quoting the Page Table Name as well.
DataObject::get("WithPreviewPage", "`WithPreviewPage`.ID IN ('8,9,10')");
-
Re: Get DataObejctSet of pages with ID filter

5 September 2009 at 11:33am
Personally I'd just Add a showPreview field to the WithPreviewPage Object that way you could filter a lot easier
That way your query could look like
$records = DataObject:get("WithPreviewPage","showPreview=1");
plus you won't need to edit the code to look for specific IDs if you want to change it later. You just click a check box in the CMS.
-
Re: Get DataObejctSet of pages with ID filter

10 September 2009 at 8:36am
Thx willr, adding the table name did the trick.
Zenmonkey, we did think of this, but we would rather select the pages to show on the homepage, and not on the individual pages.
Thank you for your answers.
| 1102 Views | ||
|
Page:
1
|
Go to Top |



