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, Ed, biapar, Willr, Ingo, swaiba

When using more images in one dataobject -> [Notice] Undefined index: uploaded_files


Go to End
Reply


2 Posts   1456 Views

Avatar
duskydesigns

Community Member, 15 Posts

25 May 2011 at 12:07am

Hey all,

I need a dataobject wich has two images, one large banner and a stamp banner. However this seems not possible with the current dataobjectmanager. I doesnt take two images. I gives a undefined index for the second image and also resets all fields set for the dataobject. I might be doing something wrong. The line it is about is:

$total = isset($_POST['totalsize']) ? $_POST['totalsize'] : sizeof($_POST['uploaded_files']);

Advertisement.php
<?php class Advertisement extends DataObject {

static $db = array (
'Name' => 'Text',
'Site' => 'Text'
);

static $has_one = array (
'Banner' => 'Image',
'Stamp' => 'Image',
'AdvertisementPage' => 'AdvertisementPage'
);

static $icon = "mysite/icons/advertisement";

public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name', 'Naam van de sponsor'),
new TextField('Site', 'URL naar de sponsor'),
new ImageField('Banner', 'Banner groot, 680x200'),
new ImageField('Stamp', 'Stamp klein, 207x200')
);
}
}
AdvertisementPage:
<?php
class AdvertisementPage extends Page {

public static $db = array(
);

static $has_many = array (
'Advertisements' => 'Advertisement'
);

public static $has_one = array(

);

static $icon = "mysite/icons/advertisementholder";

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

$manager = new FileDataObjectManager(
$this, // Controller
'Advertisements', // Source name
'Advertisement', // Source class
'Banner', // File name on DataObject
array(
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);

//$fields->addFieldToTab("Root.Content.BannerRotator", new HTMLEditorField('BannerRotator','Banner Rotator Content'));
$fields->removeFieldFromTab('Root.Content','Content');
$fields->addFieldToTab("Root.Content.Main",$manager);

// If undefined, all types are allowed. Pass with or without a leading "."
$manager->setAllowedFileTypes(array('jpg','png', 'gif'));

// Label for the upload button in the popup
$manager->setBrowseButtonText("Upload (680x200)");

// In grid view, what field will appear underneath the icon. If left out, it defaults to the file title.
$manager->setGridLabelField('Name');

// Plural form of the objects being managed. Used on the "Add" button.
$manager->setDefaultView('list');

//Remove the folder selection from uploadify
$manager->allowUploadFolderSelection = false;

//Set the upload folder
$manager->setUploadFolder('Uploads/advertisements');

return $fields;
}
}
class AdvertisementPage_Controller extends Page_Controller {

}

You can't define more than one filename on the dataobject so thats kind of hard to fix. Only other thing i can think of to fix it is to make subpages that take two images. But that is kind of overload on pages. I think this can work through the dataobjectmanager, if i can figure out what i am doing wrong.

Does it need another relationship? Im not quite sure if this is a bug or bad writing of the dataobjectmanager but i wouldve been fine with the way dataobjectmanager behaved, except for that i got undefined index and the settings of the main upload dont stick for the secondary.

Avatar
Deej

Community Member, 3 Posts

23 May 2012 at 1:12pm

Edited: 23/05/2012 2:44pm

Hi duskydesigns,

Did you ever get anywhere on this, I want to do something similar.

I want to have the main image and then be able to also be able to upload a thumbnail image all using image data object manager. At this stage I get the following error where the image upload form field for the thumbnail should be:

(note: The below is an error I get when in dev mode in test mode I don't get the error but run into more problems when I try to attach the image.)

[Notice] Undefined index: uploaded_files
GET /admin/EditForm/field/ProductImages/EditUploadedForm/field/ColourImage/iframe?SecurityID=c71f8aba608611d03d4d6a09d225f5675decea60&ctf[ProductImages][start]=0&ctf[ProductImages][per_page]=10&ctf[ProductImages][showall]=0&ctf[ProductImages][sort]=SortOrder&ctf[ProductImages][sort_dir]=&ctf[ProductImages][search]=&ctf[ProductImages][filter]=&ctf[ProductImages][view]=grid&ctf[ProductImages][imagesize]=100

Line 524 in C:\wamp\www\current\traditionalovens\implementation\public_html\dataobject_manager\code\FileDataObjectManager.php
Source

515 public function EditUploadedForm()
516 {
517 if(!$this->hasDataObject)
518 return $this->closePopup();
519
520 $childData = $this->getChildDataObj();
521 $validator = $this->getValidatorFor($childData);
522 $fields = $this->getFieldsFor($childData);
523 $fields->removeByName($this->fileFieldName);
524 $total = isset($_POST['totalsize']) ? $_POST['totalsize'] : sizeof($_POST['uploaded_files']);
525 $index = isset($_POST['index']) ? $_POST['index'] + 1 : 1;
526 $fields->push(new HiddenField('totalsize','',$total));
527 $fields->push(new HiddenField('index','',$index));
528 if(isset($_POST['uploaded_files']) && is_array($_POST['uploaded_files'])) {
529 $remaining_files = $_POST['uploaded_files'];
530 $current = $remaining_files[0];

Trace

FileDataObjectManager->EditUploadedForm(SS_HTTPRequest)
Line 143 of RequestHandler.php
RequestHandler->handleRequest(SS_HTTPRequest)
Line 161 of RequestHandler.php
RequestHandler->handleRequest(SS_HTTPRequest)
Line 161 of RequestHandler.php
RequestHandler->handleRequest(SS_HTTPRequest)
Line 147 of Controller.php
Controller->handleRequest(SS_HTTPRequest)
Line 282 of Director.php
Director::handleRequest(SS_HTTPRequest,Session)
Line 125 of Director.php
Director::direct(/admin/EditForm/field/ProductImages/EditUploadedForm/field/ColourImage/iframe)
Line 127 of main.php

Any help appreciated. Thanks.