7913 Posts in 1355 Topics by 930 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, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 3107 Views |
-
Re: Adding Files to Images within Image Gallery

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
-
Re: Adding Files to Images within Image Gallery

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?
-
Re: Adding Files to Images within Image Gallery

6 September 2010 at 10:01pm Last edited: 6 September 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
-
Re: Adding Files to Images within Image Gallery

6 September 2010 at 10:16pm Last edited: 6 September 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
-
Re: Adding Files to Images within Image Gallery

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
-
Re: Adding Files to Images within Image Gallery

6 September 2010 at 10:31pm
are you using rev 481?
SVN: http://carlinowebdesign.svn.beanstalkapp.com/modules/trunk/dataobject_manager
-
Re: Adding Files to Images within Image Gallery

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
Source384 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.phpAfter 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
-
Re: Adding Files to Images within Image Gallery

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.phpMatt
| 3107 Views | ||
| Go to Top | Next > |

