Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [SOLVED] How to get an array of pages ID?

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

Page: 1
Go to End
Author Topic: 1133 Views
  • Digital-Punk.co.uk
    Avatar
    Community Member
    51 Posts

    [SOLVED] How to get an array of pages ID? Link to this post

    Hi there

    I'm trying to get automatically an array of pages id (in ex. 29,38):

    function GetCategoryNews() {
        $holderid = DataObject::get("NewsHolder","ParentID = $this->ID");
    ...
        $doSet = DataObject::get(
          $callerClass = "NewsPage",
          $filter = "`SiteTree`.ParentID IN (29,38)",
          $sort = "Date DESC",
          $join = "",
          $limit = ""
        );
        return $doSet ? $doSet : false;
       }

    Maybe someone has an example how to get an array of pages ID or can help with this?

    Best regards
    Mindaugas

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: [SOLVED] How to get an array of pages ID? Link to this post

    Sorry not sure I completely understand you here. The code you provided would get all the newspages which have the parents IDs of 29 or 38 that should work fine.

    However your title suggests you want an array of all the Page ID's. For that you can use the map() method on any dataobjectset to return an array from a dataobjectset.

  • Digital-Punk.co.uk
    Avatar
    Community Member
    51 Posts

    Re: [SOLVED] How to get an array of pages ID? Link to this post

    No worries, I found solution - just made "holderid" as array:

    $filter = "`SiteTree`.ParentID IN ($holderid)"

    Anyway, thanks for the response!

    1133 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.