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:

Template Questions /

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

Using multileveled DataObjectSets in a control?


Go to End


2 Posts   1657 Views

Avatar
patrik

Community Member, 9 Posts

8 July 2009 at 2:32am

Edited: 08/07/2009 2:34am

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!

Avatar
patrik

Community Member, 9 Posts

8 July 2009 at 10:48pm

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);
}
}