7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » many Attachments on FileDataObjectManager
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | ||
| Author | Topic: | 3065 Views |
-
Re: many Attachments on FileDataObjectManager

4 February 2011 at 7:39am
Great!!!
That's exactly that i need!
;-)
thanks so much UncleCheese
-
Re: many Attachments on FileDataObjectManager

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 DataObjectHistoryDateItems 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.
-
Re: many Attachments on FileDataObjectManager

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!
-
Re: many Attachments on FileDataObjectManager

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'.
-
Re: many Attachments on FileDataObjectManager

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?
-
Re: many Attachments on FileDataObjectManager

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.
-
Re: many Attachments on FileDataObjectManager

4 March 2011 at 7:30am
Thank you UncleCheese! I will give that a whirl!
-
Re: many Attachments on FileDataObjectManager

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
| 3065 Views | ||
| Go to Top |



