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

Default Upload Folder (DOM with Nested FileDOM)


Go to End
Reply


3 Posts   1125 Views

Avatar
Hello_electro

Community Member, 80 Posts

19 February 2011 at 5:24am

Edited: 19/02/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

$manager->setUploadFolder('SafetyAZImages');
but am guessing it has to change a bit to accommodate the nested object. Here is the code:

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')
			
		);
			
	}
}
?>

Avatar
UncleCheese

Forum Moderator, 4096 Posts

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

Avatar
Hello_electro

Community Member, 80 Posts

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.