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

Adding Files to Images within Image Gallery


Reply


21 Posts   4003 Views

Avatar
adesweb

Community Member, 39 Posts

3 September 2010 at 3:12am

Hi,

Had the same issue. This works, but the first time I upload, and then try and upload the thumbnail in the imageField, I get the following error:

Fatal error: Call to a member function write() on a non-object in /home/adrianw/PROJECTS/bcl/website2009/sapphire/forms/FileIFrameField.php on line 209

Please can someone help?

Adrian

Avatar
mattclegg

Community Member, 56 Posts

5 September 2010 at 1:56pm

Hey adesweb,

I presume you made the change to line 493 of FileDataObjectManager.php ?

Can you show some code?

Avatar
adesweb

Community Member, 39 Posts

6 September 2010 at 10:01pm

Edited: 06/09/2010 10:02pm

Changed 393 of FileDataObjectManager to:

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

My code is for the particular DataObject I am using:

<?
class CaseStudyImage extends DataObject
{
   static $db = array (
      'Name' => 'Varchar'   
   );
   
   static $has_one = array (
      'Attachment' => 'Image',
      'Thumbnail' => 'Image',
      'CaseStudyPage' => 'CaseStudyPage'
   );
   
   public function getCMSFields_forPopup()
   {
      $f = new FieldSet();
      $f->push(new ImageField('Thumbnail'));
      $f->push(new TextField('Name'));
      $f->push(new ImageField('Attachment'));
      return $f;
   }
   
   
}
?>

The relevant code in my class CaseStudyPage is:

static $has_many = array ('CaseStudyImages' => 'CaseStudyImage');


and

$manager = new FileDataObjectManager(
         $this, // Controller
         'CaseStudyImages', // Source name
         'CaseStudyImage', // Source class
         'Attachment', // File name on DataObject
         array(
            'Name' => 'Name'
         ), // Headings
         'getCMSFields_forPopup',// Detail fields (function name or FieldSet object)
         "", // Filter clause,
         "Name Asc"    // Sort clause
         // Join clause
         // Join clause
      );
      $manager->setAllowedFileTypes(array("jpg"));
      $f->addFieldToTab("Root.Content.AdditionalImages",$manager);

Let me know if you need any other code

Avatar
mattclegg

Community Member, 56 Posts

6 September 2010 at 10:16pm

Edited: 06/09/2010 10:16pm

Hey Adesweb,

I see you have shruk my if statements, but can you set the count to 1? And post on here if it works?

I think using 0 seems to make the last if pointless in this context.

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

And for anyone else reading its line 493

Avatar
adesweb

Community Member, 39 Posts

6 September 2010 at 10:28pm

hmm, 1 doesn't seem to work either.

It does seem to be line 393 btw, within function EditUploadedForm? Or is this wrong? Am I using the wrong version of the file?

Adrian

Avatar
mattclegg

Community Member, 56 Posts

6 September 2010 at 10:31pm

are you using rev 481?

SVN: http://carlinowebdesign.svn.beanstalkapp.com/modules/trunk/dataobject_manager

Avatar
adesweb

Community Member, 39 Posts

6 September 2010 at 10:52pm

Yes I am, I've just replaced the module with files from that SVN location just to make sure.

The initial error within the thumbnail image field area I was getting on adding a new CaseStudyImage was:

[Notice] Undefined index: uploaded_files
GET /admin/EditForm/field/CaseStudyImages/EditUploadedForm/field/Thumbnail/iframe?ctf[CaseStudyImages][start]=0&ctf[CaseStudyImages][per_page]=10&ctf[CaseStudyImages][showall]=0&ctf[CaseStudyImages][sort]=SortOrder&ctf[CaseStudyImages][sort_dir]=Asc&ctf[CaseStudyImages][search]=&ctf[CaseStudyImages][filter]=&ctf[CaseStudyImages][view]=

Line 393 in /home/adrianw/PROJECTS/bcl/website2009/dataobject_manager/code/FileDataObjectManager.php
Source

384    public function EditUploadedForm()
385    {
386       if(!$this->hasDataObject)
387          return $this->closePopup();
388
389       $childData = $this->getChildDataObj();
390       $validator = $this->getValidatorFor($childData);
391       $fields = $this->getFieldsFor($childData);
392       $fields->removeByName($this->fileFieldName);
393       $total = isset($_POST['totalsize']) ? $_POST['totalsize'] : sizeof($_POST['uploaded_files']);
394       $index = isset($_POST['index']) ? $_POST['index'] + 1 : 1;
395       $fields->push(new HiddenField('totalsize','',$total));
396       $fields->push(new HiddenField('index','',$index));
397       if(isset($_POST['uploaded_files']) && is_array($_POST['uploaded_files'])) {
398          $remaining_files = $_POST['uploaded_files'];
399          $current = $remaining_files[0];

Trace

* FileDataObjectManager->EditUploadedForm(SS_HTTPRequest)
Line 137 of RequestHandler.php
* RequestHandler->handleRequest(SS_HTTPRequest)
Line 155 of RequestHandler.php
* RequestHandler->handleRequest(SS_HTTPRequest)
Line 155 of RequestHandler.php
* RequestHandler->handleRequest(SS_HTTPRequest)
Line 147 of Controller.php
* Controller->handleRequest(SS_HTTPRequest)
Line 281 of Director.php
* Director::handleRequest(SS_HTTPRequest,Session)
Line 124 of Director.php
* Director::direct(/admin/EditForm/field/CaseStudyImages/EditUploadedForm/field/Thumbnail/iframe)
Line 127 of main.php

After replacing line 393 from:

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

to

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

I can then upload the file but on trying to upload a thumbnail, I get:

Fatal error: Call to a member function write() on a non-object in /home/adrianw/PROJECTS/bcl/website2009/sapphire/forms/FileIFrameField.php on line 209

Thanks for your assistance with this

Adrian

Avatar
mattclegg

Community Member, 56 Posts

6 September 2010 at 11:30pm

Hi Adrian,

After you have saved 'CaseStudyImage' can you edit the Thumbnail?

Also you can get the live version from here, and you should see it is line 493;
http://carlinowebdesign.svn.beanstalkapp.com/modules/trunk/dataobject_manager/code/FileDataObjectManager.php

Matt