Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Adding Files to Images within Image Gallery

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3
Go to End
Author Topic: 3798 Views
  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    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

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    Hey adesweb,

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

    Can you show some code?

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    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

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    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

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    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

  • mattclegg
    Avatar
    Community Member
    56 Posts
  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    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

  • mattclegg
    Avatar
    Community Member
    56 Posts

    Re: Adding Files to Images within Image Gallery Link to this post

    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

    3798 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.