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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Dataobject::get from multiple classes


Go to End


5 Posts   2391 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, 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.

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