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

Problem while uploading multiple images


Go to End


1952 Views

Avatar
neerom

Community Member, 8 Posts

2 June 2013 at 12:46am

Hi,
I am trying to upload multiple photos with a caption.
But after adding caption for all the uploaded pictures, when i click 'finish' button, it does not come back to the page it started from.

Please help..

Homepage.php:
<?php
/**
* Defines the HomePage page type
*/

class HomePage extends Page {
static $db = array(
'Description' => 'Text'

);
static $has_one = array(
'ProfileImage' => 'CustomImage'
);

public static $has_many = array(
'AttachedFiles' => 'SlideShow',
'AttachedPhotos' => 'PhotoStream',
'HolidayPictures' => 'HolidayPicture'

);

public function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Main', new FileUploadField('ProfileImage', 'Upload a profile image'));

/* Add the code below this line */
// This adds a DataObjectManager to a new tab
$manager = new ImageDataObjectManager(
$this,
'HolidayPictures',
'HolidayPicture',
'Attachment',
array(
'Caption' => 'Caption'
),
'getCMSFields_forPopup'
);
$fields->addFieldToTab("Root.Content.HolidayPictures", $manager);

return $fields;
}

}

class HomePage_Controller extends Page_Controller {

public function init()
{
parent::init();

}

}

and HolidayPictures.php:

<?php
class HolidayPicture extends DataObject
{
static $db = array (
'Caption' => 'Text'
);

static $has_one = array (
'Attachment' => 'CustomImage',
'EmployeePage' => 'EmployeePage'

);

public function getCMSFields_forPopup()
{
return new FieldSet(
new FileUploadField('Attachment', 'Add a holiday picture'),
new TextAreaField('Caption', 'Add a caption')
);
}
}