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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

many Attachments on FileDataObjectManager


Go to End


24 Posts   5985 Views

Avatar
jmax

Community Member, 17 Posts

4 February 2011 at 7:39am

Great!!!

That's exactly that i need!

;-)

thanks so much UncleCheese

Avatar
moloko_man

Community Member, 72 Posts

12 February 2011 at 6:44am

I'm building a historic timeline of sorts using a nested DataObjectManager, and my structure is currently like this:

HistoryPage extends Page has_many HistoryDate
HistoryDate extends DataObject has_many HistoryDateItem
HistoryDateItem extends DataObject

HistoryDateItems can consist of a Picture, Quote, Story, or Stats.
HistoryDateItems will NEVER be more than 8 items.

everything is pretty much working but when I open the window for the nested DOM its only 433px wide. Is there a way to set the width of a nested DOM object?
I've tried using $nestedDOM->setPopupWidth('600'); but no workie.

Also, just looking for some friendly advice on this, but for my HistoryDateItem, is a DataObject the best route to take for this?
The Timeline looks like this - https://img.skitch.com/20110211-fx4max63nmensgbygriuqj4bi7.jpg
when the items underneath the date are clicked they open a "lightbox" type window with the Picture, quote or whatever inside said window.

Thanks.

Avatar
VanceK

Community Member, 18 Posts

4 March 2011 at 4:49am

Hi Unclecheese, thank you for all your hard work on the DataObjectManager.

I have a need to attach multiple files to Silverstripe pages and keep bouncing my head against the wall trying to get this to work correctly.

I started with the code you posted in this thread on 2 February 2011 at 4:04am, where you listed three files: ResourcePage.php, Resource.php, and ResourceFile.php. Originally, I was getting errors with the $manager-> modifiers until I changed the line $manager = new DataObjectManager(...) to $manager = new FileDataObjectManager(...).

I understand that I need to insert another parameter into the construct after the source class for a "File name on DataObject" but I can't seem to figure out just what to use there. It seems no matter what I try the CMS keeps dying with the error "FileDataObjectManager::__construct():Could not determine file relationship". Using your example code as a start could you shed light on what I need to use there?

Also, utilizing this example will I be able to attach the same multiple files to multiple pages. (ie File1 & File2 attached to both Page1 and Page2)?

Thanks!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

4 March 2011 at 4:58am

Whatever the file relationship you have on your DataObject, put that as the fourth argument. So if your DataObject has a $has_one 'MyFile' => 'File', then use 'MyFile'.

Avatar
VanceK

Community Member, 18 Posts

4 March 2011 at 5:18am

Thanks for the fast response!

Sorry for my inexperience in this, but I'm new to Silverstripe and still a little unsure what to use. Following the code from the example, I have three files with the following setup:

File: ResourcePage.php

class ResourcePage extends Page
{
static $has_many = array (
'Resources' => 'Resource'
);

public function getCMSFields()
{
$f = parent::getCMSFields();
$manager = new FileDataObjectManager(
$this, // Controller
'Resources', // Source name
'Resource', // Source class
'?', // File name on DataObject
array(
'Name' => 'Name',
'Description' => 'Description',
'Category' => 'Category',
'Attachment.Name' => 'Attachment',
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
...

File: Resource.php

class Resource extends DataObject
{
static $db = array (
'Name' => 'Text',
'Description' => 'Text',
'Category' => "Enum('Industry, Finance, Education')",
);

static $has_one = array (
'ResourcePage' => 'ResourcePage'
);

static $has_many = array (
'Attachments' => 'ResourceFile'
);
...

File: ResourceFile.php

class ResourceFile extends File
{
static $has_one = array (
'Resource' => 'Resource'
);

Which label would I use as the fourth argument?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

4 March 2011 at 7:15am

This doesn't work:

static $has_many = array (
'Attachments' => 'ResourceFile'
);

FileDOM is for DataObjects with a has_one file.

You can use a regular DOM to manage those Resources and just use a MultipleFileUploadField for the Attachments field. You'll have to either decorate the File class or create a file subclass to put a has_one Resource on the File.

Avatar
VanceK

Community Member, 18 Posts

4 March 2011 at 7:30am

Thank you UncleCheese! I will give that a whirl! :)

Avatar
bunheng

Community Member, 78 Posts

6 June 2011 at 1:18pm


Good morning UncleCheese,

Is it possible way to have category from other table.

Thanks in advance for your reply.

Regards,
Bunheng

Go to Top