Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Using page with DOM multiple times

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: 599 Views
  • Guy Van Bael
    Avatar
    Community Member
    33 Posts

    Using page with DOM multiple times Link to this post

    Hi,

    I'm experiencing a problem with Filedom. I created a download class and a dowloadPage. All works fine, but when i create second page in the siteroot with this downloadpage template and when i display the items in the dom, all the downloads show up (also the ones from the first page in the siteroot).

    Is there any way to add some kind of filter so that page1 shows only the entries in the dom for page one and page2 shows only the entries from the page2 dom?

    this is my code so far:

    Download.php
    <?php
    class Download extends DataObject
    {
       static $db = array (
          'Naam' => 'Text',
          'Omschrijving' => 'Text',
       );

       static $has_one = array (
          'Bijlage' => 'File',
          'DownloadPage' => 'DownloadPage'
       );

       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Naam'),
             new TextareaField('Omschrijving'),
             new FileIFrameField('Bijlage')
          );
       }
    }

    ?>

    DownloadPage.php

    <?php
    class DownloadPage extends Page
    {
       static $has_many = array (
          'Bijlagen' => 'Download'
       );

       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new FileDataObjectManager(
             $this, // Controller
             'Bijlagen', // Source name
             'Download', // Source class
             'Bijlage', // File name on DataObject
             array(
                'Naam' => 'Name',
                'Omschrijving' => 'Description',
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
    $f->addFieldToTab("Root.Content.Downloads",$manager);
    return $f;
       }
    }
    class DownloadPage_Controller extends Page_Controller {

          function AllDownloads() {
          
             $bijlagen = DataObject::get_one("DownloadPage");
             return ($bijlagen) ? DataObject::get("Download","", "", "", "") : false;
          }
       
       };

    ?>

  • rob.s
    Avatar
    Community Member
    78 Posts

    Re: Using page with DOM multiple times Link to this post

    Hi Guy,

    try:

    class DownloadPage_Controller extends Page_Controller {

    function AllDownloads() {

    return $this->data()->Bijlagen();
    }

    };

    $this->data() gets the DataRecord as DataObject and ->Bijlagen() gets the Downloads as DataObjectSet, as you defined in has_many.

    Greetings,

    Robert

  • Guy Van Bael
    Avatar
    Community Member
    33 Posts

    Re: Using page with DOM multiple times Link to this post

    Hi Rob,

    Thanx for the fast reply. Your solution works like a charm!

    Fantastic.

  • rob.s
    Avatar
    Community Member
    78 Posts

    Re: Using page with DOM multiple times Link to this post

    it's not my solution - it's sapphire

    Rob

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