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

Using page with DOM multiple times


Reply


4 Posts   636 Views

Avatar
Guy Van Bael

Community Member, 35 Posts

23 December 2010 at 7:25am

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

?>

Avatar
rob.s

Community Member, 78 Posts

23 December 2010 at 8:27am

Edited: 23/12/2010 8:32am

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

Avatar
Guy Van Bael

Community Member, 35 Posts

23 December 2010 at 9:08am

Hi Rob,

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

Fantastic.

Avatar
rob.s

Community Member, 78 Posts

23 December 2010 at 9:20am

it's not my solution - it's sapphire :-)

Rob