7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Default Upload Folder (DOM with Nested FileDOM)
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 737 Views |
-
Default Upload Folder (DOM with Nested FileDOM)

19 February 2011 at 5:24am Last edited: 19 February 2011 5:25am
Hi All:
I have a Dataobject set up with a nested FileDataObect. I am trying to set the default upload folder for the FileDataObject, but keep getting the error message that the "method 'setuploadfolder' does not exist on 'DataObjectManager'"
I understand why, which is because the DataObject is not a file. So I am unsure where I am supposed to note the default upload folder for the nested FileDOM. Can someone point out where it should go? I have the following snippit
but am guessing it has to change a bit to accommodate the nested object. Here is the code:$manager->setUploadFolder('SafetyAZImages');
Thanks as always for the support!
SafetyAZPage.php
class SafetyAZPage extends Page
{
static $has_many = array (
'SafetyAZItems' => 'SafetyAZItem'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$manager = new DataObjectManager(
$this, // Controller
'SafetyAZItems', // Source name
'SafetyAZItem', // Source class
array('AZTitle' => 'AZTitle'), // Headings
'getCMSFields_forPopup' // Detail fields function or FieldSet
// Filter clause
// Sort clause
// Join clause
);
$f->addFieldToTab("Root.Content.SafetyAZItems", $manager);
return $f;
}}
SafetyAZItem.php
<?php
class SafetyAZItem extends DataObject
{
static $db = array (
'AZTitle' => 'Text',
'AZContent' => 'Text'
);
static $has_one = array (
'SafetyAZPage' => 'SafetyAZPage'
);
static $has_many = array (
'SafetyAZImages' => 'SafetyAZImages'
);
public function getCMSFields()
{
return new FieldSet(
new TextField('AZTitle'),
new TextareaField('AZContent'),
new FileDataObjectManager(
$this,
'SafetyAZImages',
'SafetyAZImage',
'AZImage',
array('AZImageTitle' => 'AZImageTitle',
'AZImageCaption' => 'AZImageCaption')
)
);
}
}
?>SafetyAZImage.php
<?php
class SafetyAZImage extends DataObject
{
static $db = array (
'AZImageTitle' => 'Text',
'AZImageCaption' => 'Text'
);
static $has_one = array (
'SafetyAZItem' => 'SafetyAZItem',
'AZImage' => 'File'
);
function getCMSFields()
{
return new FieldSet(
new TextField('AZImageTitle'),
new TextField('AZImageCaption'),
new FileIFrameField('AZImage')
);
}
}
?> -
Re: Default Upload Folder (DOM with Nested FileDOM)

19 February 2011 at 5:41am
What about this:
public function getCMSFields()
{
$f = new FieldSet(
new TextField('AZTitle'),
new TextareaField('AZContent'),
$fdom = new FileDataObjectManager(
$this,
'SafetyAZImages',
'SafetyAZImage',
'AZImage',
array('AZImageTitle' => 'AZImageTitle',
'AZImageCaption' => 'AZImageCaption'))
);
$fdom->setUploadFolder("foo");
return $f;
} -
Re: Default Upload Folder (DOM with Nested FileDOM)

22 February 2011 at 5:35am
You're the man! Thanks UC!
Also:
I noticed in SafetyAZItem.php I had:
static $has_many = array (
'SafetyAZImages' => 'SafetyAZImages'
);should it actually be...
static $has_many = array (
'SafetyAZImages' => 'SafetyAZImage'
);or does that not matter?
I did change it to the latter though.
| 737 Views | ||
|
Page:
1
|
Go to Top |

