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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

Dataobject::get from multiple classes

Go to End

5 Posts   2082 Views


Community Member, 131 Posts

7 February 2010 at 12:05pm

Edited: 07/02/2010 12:06pm


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."'",

  return $thedata ? $thedata : false;


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


Forum Moderator, 5523 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.


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.


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?


Community Member, 712 Posts

8 February 2010 at 10:23pm