Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Getting proper data from Nested DOM

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 705 Views
  • socks
    Avatar
    Community Member
    190 Posts

    Getting proper data from Nested DOM Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Getting proper data from Nested DOM Link to this post

    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 %>

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Getting proper data from Nested DOM Link to this post

    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.

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