Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Dataobject::get from multiple classes

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

Page: 1
Go to End
Author Topic: 1433 Views
  • theAlien
    Avatar
    Community Member
    131 Posts

    Dataobject::get from multiple classes Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Dataobject::get from multiple classes Link to this post

    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.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Dataobject::get from multiple classes Link to this post

    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.

  • theAlien
    Avatar
    Community Member
    131 Posts

    Re: Dataobject::get from multiple classes Link to this post

    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?

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Dataobject::get from multiple classes Link to this post

    Correct

    1433 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.