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.

Customising the CMS /

Dataobject::get from multiple classes


Reply


5 Posts   1567 Views

Avatar
theAlien

Community Member, 131 Posts

7 February 2010 at 12:05pm

Edited: 07/02/2010 12:06pm

Hi,

How do I get the data of many pagetypes into one sorted list on the HolderPage?
I tried something like this:

function MyData() {
if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
$SQL_start = (int)$_GET['start'];

$thedata = Dataobject::get(
"Pagetype1 OR Pagetype2 OR Pagetype3",
"`ParentID` = '".$this->ID."'",
"",
"",
"{$SQL_start},2"
);

return $thedata ? $thedata : false;

}


But apparently that didn't work. Has someone tried this before? Or has someone an idea of what to do?

Avatar
Willr

Forum Moderator, 5513 Posts

7 February 2010 at 1:43pm

Probably the easiest way is to do 3 DataObject calls - 1 for each page type and then use $set->merge($set2) to merge the sets together. You can then filter / sort the final set as 1.

Avatar
ajshort

Community Member, 244 Posts

7 February 2010 at 10:32pm

Alternatively, if all your DataObjects extend from the same class, you can simply query for instances of that parent class. You said that you have three page types, so if you simply query for "Page" it will return your page subclass objects.

Avatar
theAlien

Community Member, 131 Posts

8 February 2010 at 1:57pm

Hi, thanks for your answers.

ajshort, you're right: they're all subclasses of page.
Do you mean Dataobject::get('Page', etcetera... will get Page and all it's subclasses?

Avatar
Hamish

Community Member, 712 Posts

8 February 2010 at 10:23pm

Correct