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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Getting proper data from Nested DOM


Reply


3 Posts   760 Views

Avatar
socks

Community Member, 191 Posts

20 August 2010 at 4:18pm

I'm having issues getting the correct data with my Nested DOM. All works except that, so far, I've attached 3 photos to the first room, and it's returning those 3 photos for every Room. I figured that I needed a filter by ID of some sort for the GetRoomPhotos(), but nothing I tried worked.

My RoomsPage lists multiple Rooms (DOM). Each Room has it's own RoomPhoto gallery (Image DOM).

class RoomsPage_Controller extends Page_Controller {

   function GetRooms() {
      return DataObject::get('Room');
      
   }
   
   function GetRoomPhotos() {
      return DataObject::get('RoomPhoto');   
   }
   
}

In the Template (RoomsPage.ss)

<% control GetRooms %>
...
   <% control Top.GetRoomPhotos %>...<% end_control %>
   
<% end_control %>

Here's the full source from the 3 PHP pages if it helps... http://pastie.textmate.org/private/a8scxavuf4v8puuc5wfs5w

Thank you

Avatar
UncleCheese

Forum Moderator, 4096 Posts

21 August 2010 at 1:45am

Look at your two functions. They both return the world of all Rooms or Photos, without regard to the containing object. Get rid of both of those functions.

RoomsPage.ss.

<% control Rooms %>
$RoomName
<% control RoomPhotos %>
$Attachment
<% end_control %>
<% end_control %>

Avatar
socks

Community Member, 191 Posts

22 August 2010 at 6:38am

Hey Uncle C,

Thanks for your help. I tried ditching the functions and changing the template but it wasn't showing any of the photos, the room info was displaying properly.

I then changed 2 things,
- Room.php: my nested ImageDataObjectManager to FileDataObjectManager
- RoomPhoto.php: Attachment => Image to Attachment => File

And it started working. Trying to get it to break again, I then restored my files to the earlier versions but it still works. So I'm not sure what was going on.