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

Attach Image to Page with Uploadify


Go to End


756 Views

Avatar
Tama

Community Member, 138 Posts

1 November 2011 at 4:00pm

We want to use Uploadify so CMS users can simply upload images that are then attached to Pages. At the basic level this is the code:

class Page extends SiteTree {

	static $has_many = array(
		"PageImages" => "PageImage"
	);

	function getCMSFields(){
		$fields = parent::getCMSFields();
		$fields->addFieldToTab("Root.Content.PageImages", new MultipleFileUploadField('PageImages','Add Images to Page'));		
		return $fields;
	}
}

class PageImage extends Image {
	
 	static $has_one = array(
		"Page" => "Page"
	);
	
}

However when a file is Uploaded through the "Upload New" tab it isn't automatically attached to the page. We thought this would be the default behaviour.

Instead CMS users have to click on the "Choose existing" tab and select/ Import the images they are after.

I'm guessing we've missed something very very simple, any help would be appreciated.