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, simon_w

problems with imagedataobject_manager..


Reply


368 Views

Avatar
zim

Community Member, 135 Posts

18 October 2011 at 9:55pm

I have created an event object that stores various datatypes including two extra images... as follows

<?php

class Event extends DataObject
{
   static $db = array (
      'DateStart' => 'Date',
      'DateFinish' => 'Date',
      'Name' => 'Text',
      'Time_Price' => 'Text',
      'Copy' => 'HTMLText',
      'WebLink' => 'Text',
      
   );
   
   static $has_one = array (
      'Attachment' => 'Image',
      'Attachment2' => 'Image',
      'Attachment3' => 'Image',
      'EventsHolder' => 'EventsHolder'
   );
   
   public function getCMSFields_forPopup()
   {
      return new FieldSet(
         new DatePickerField('DateStart'),
         new DatePickerField('DateFinish'),
         new TextField('Name'),
         new TextField('Time_Price'),
         new TextareaField('Copy'),
         new TextField('WebLink'),
         
         new FileIFrameField('Attachment'),
         new ImageField('Attachment2'),
         new ImageField('Attachment3')
      );
   }
}

?>

i also have an events_holder page as follows

<?php
/**
* Defines the EventsHolder page type
*/

class EventsHolder extends Page {
static $db = array(       
      
);

static $has_one = array(
            
);

static $has_many = array (
      'Events' => 'Event'
   );

function getCMSFields() {
    $fields = parent::getCMSFields();
   
    $manager = new ImageDataObjectManager(
         $this, // Controller
         'Events', // Source name
         'Event', // Source class
         'Attachment', // File name on DataObject
         array(
            'DateStart' => 'Date',
            'DateFinish' => 'Date',
            'Name' => 'Name',
            'Time_Price' => 'Time_Price',
            'Copy' => 'Copy',
            'WebLink' => 'WebLink',
            'Attachment2' => 'Attachment2',
            'Attachment3' => 'Attachment3'
            
         ), // Headings
         'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
         // Filter clause
         // Sort clause
         // Join clause
      );
   
   
    $fields->addFieldToTab("Root.Content.Events",$manager);
      
    return $fields;
   }

}

class EventsHolder_Controller extends Page_Controller {

}
?>

.... now the problem arises when i try to save the two extra images the first time I enter a new Event object.. this causes an error.. however the new event does save and when i go back to edit the event i can then enter and save the two extra images as normal.... Does this make sense and dose anyone know why this this might be happening?

Is the imagedata0bjectmanager the best one to use for this or should i be just using filedataobjectmanager... or even just complex table field.

any advice much appreciated