I have a StoreLocation DataObject. I want to list all stores grouped by State then by City.
I borrowed code from this post: http://silverstripe.org/dataobjectmanager-module-forum/show/267505#post267505 and that got me halfway there.
The page is properly grouping by State (and only listing each state one time), but I now need to get it to group by City as well. (See Screenshot)
This is what I have so far (just a direct copy from other post)
class StoreLocationsPage_Controller extends Page_Controller {
function Locations() {
$States = new DataObjectSet();
$results = DB::query("SELECT DISTINCT State FROM StoreLocation ORDER BY State ASC");
if($results) {
foreach($results as $result) {
$state = $result['State'];
$States->push(new ArrayData(array(
'State' => $state,
'Locations' => DataObject::get("StoreLocation","State = '$state'", 'Name')
)));
}
return $States;
}
return false;
}
}
Any help is much appreciated, Thanks.