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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

FileDataObjectManager Issue


Go to End


3 Posts   1067 Views

Avatar
aTTi

Community Member, 19 Posts

9 March 2010 at 11:04pm

Edited: 09/03/2010 11:39pm

Hey Guys

I'm using the FileDataObjectManager and have (I guess) 1 simple Problem.

I created a FileDataObject Called "Downloads" where I can add some Files to download.
When I creat another Page with the Download section included and add there different Files the output looks like:

Testsite1

added blabla.pdf
output -> blabla.pdf

Testsite 2
added blua.pdf
output -> blabla.pdf
blua.pdf

SourceCode:

image_gallery/code/Download.php

class Download extends DataObject {

static $db = array (
'Name' => 'Text',
);

static $has_one = array (
'Attachment' => 'File',
'ImageGalleryPage' => 'ImageGalleryPage'
);

public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new FileIFrameField('Attachment')
);
}

}

/images_gallery/code/ImageGalleryPage.php:

$manager = new FileDataObjectManager(
$this,
'Downloads',
'Download',
'Attachment',
array (
'Name' => 'Name'
),
'getCMSFields_forPopup');
$f->addFieldToTab("Root.Content.Downloads",$manager);

function Download() {
$DownloadData = DataObject::get("Download","ID = ".$this->ID); //I Also tried "Download","ParentID = ".$this->ID
return $DownloadData;
}

Is there a solution for this? I only want to Publish the Files from the Current Sites.

Sorry for my bad english

Best regards aTTi

Avatar
aTTi

Community Member, 19 Posts

9 March 2010 at 11:46pm

...Solved my Problem.

For others:

The Problem was, there are 3 "ID's" in the Database

ID (DB-ID)
AttachmentID
ImageGalleryPageID

So i just had to rewrite the function Download like:

function Download() {
$DownloadData = DataObject::get("Download","ImageGalleryPageID = ".$this->ID);
return $DownloadData;
}

Best regards,

aTTi

Avatar
UncleCheese

Forum Moderator, 4102 Posts

10 March 2010 at 3:01am

Your function isn't necessary, because you already have a relation defined as "Downloads"..

$this->Downloads() will give you what you need.