Jump to:

3439 Posts in 1028 Topics by 869 members

Template Questions

SilverStripe Forums » Template Questions » Using multileveled DataObjectSets in a control?

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

Page: 1
Go to End
Author Topic: 1212 Views
  • patrik
    Avatar
    Community Member
    9 Posts

    Using multileveled DataObjectSets in a control? Link to this post

    Hi!

    I have a method in my controller which collects data like this:

    public function GetData() {
       $sqlQuery = new SQLQuery();
       $sqlQuery->select("website");
       $sqlQuery->from("listsitem");
       $sqlQuery->groupby("website");
       $result = $sqlQuery->execute();
       $data = new DataObjectSet();
          
       foreach($result as $row) {
          $data->push(DataObject::get("ListsItem", "website ='".$row['website']."'", "", "", 2));

       }
    }

    Before i did like this.
    public function GetData() {
       return DataObject::get("ListsItem", "website ='".$row['website']."'", "", "", 2));
    }
    And that worked fine with just:
    <% control GetData %>
    ...
    <% end_control%>

    But how do i use the values from the dataset if its a multilevel array? I can't seem to find anything about this in the manual.

    I would be very grateful for help with this!

  • patrik
    Avatar
    Community Member
    9 Posts

    Re: Using multileveled DataObjectSets in a control? Link to this post

    Anyway, i solved it by iterating in the controller, instead of the template

    $data = new DataObjectSet();
       foreach($result as $row) {
          $tmpRes = DataObject::get("ListsItem", "website ='".$row['website']."', "", "", 2);
          foreach($tmpRes as $t) {
             $data->push($t);
          }
       }

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