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   1504 Views

Avatar
theAlien

7 February 2010 at 12:05pm (Last edited: 7 February 2010 12:06pm), Community Member, 131 Posts

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

7 February 2010 at 1:43pm Forum Moderator, 5511 Posts

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

7 February 2010 at 10:32pm Community Member, 244 Posts

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

8 February 2010 at 1:57pm Community Member, 131 Posts

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

8 February 2010 at 10:23pm Community Member, 712 Posts

Correct