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

What to do if I want to use the DataObjectManager with different types of pages?


Go to End


2 Posts   1193 Views

Avatar
WebSpilka

Community Member, 89 Posts

3 October 2009 at 4:00am

Now I add photos to the FotoPage with DataObjectManager (Class Foto):

class Foto extends DataObject
{
	static $db = array (
		'Name' => 'Text',
		'Description' => 'Text',
	);
	
	static $has_one = array (
		'Attachment' => 'File',
		'FotoPage' => 'FotoPage'
	);
	
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('Name'),
			new TextareaField('Description'),
			//new DropdownField('Category','Category', singleton('Resource')->dbObject('Category')->enumValues()),
			new FileIFrameField('Attachment')
		);
	}
}

what should I do to use the module on different types of pages: FotoPage and NewsPage?
may be sufficient to fix the code only:
'FotoPage' => 'FotoPage'
on
'FotoPage' => 'Page'
?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

3 October 2009 at 4:03am

You can add as many relations as you want.

static $has_one = array (
'Attachment' => 'File',
'FotoPage' => 'FotoPage',
'SomeOtherPage' => 'SomePage',
'AnotherPage' => 'AnotherPage'
);