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.

Customising the CMS /

Unable to display uploaded files


Go to End
Reply


9 Posts   2636 Views

Avatar
SamSmooth

Community Member, 18 Posts

30 September 2010 at 6:09am

I am trying to manage multiple files with one page.

This is what I have so far:

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

static $has_one = array(
'RootFolder' => 'Folder'
);

static $has_many = array(
'ProductDownloads' => 'ProductDownload',
);

function getCMSFields() {

$fields = parent::getCMSFields();

    $downloadtable = new ComplexTableField(
   $this,
'ProductDownloads', // relation name
'ProductDownload', // object class
ProductDownload::$field_names, // fields to show in table
ProductDownload::getCMSFields_forPopup(), // form that pops up for edit
"ProductPageID = {$this->ID}", // a filter to only display item associated with this page
"Position ASC" // Sort by name
    );
    $fields->addFieldToTab('Root.Content.Downloads', $downloadtable);

return $fields;
}

}


class ProductDownload extends DataObject {
static $db = array(
'Title' => 'Text',
    'Position' => 'Int',
);

static $has_one = array(
'File' => 'File',
'ProductPage' => 'ProductPage',
'RootFolder' => 'Folder'
);

static $field_names = array(
'Title' => 'Title',
'File' => 'File',
);

function getCMSFields_forPopup() {

$fields = new FieldSet();

    $fields->push(new TextField('Title', 'Title'));

    $folderName = $this->RootFolder()->FileName;
    $folderName = str_replace('assets/','',$folderName);
   
    $fields->push(new FileField("File", "File", null, null, null, $folderName));

    $fields->push(new TextField('Position', 'Position'));

return $fields;
}

}

I get the following error after uploading a new file:

Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'File' IN POST /admin/EditForm/field/ProductDownloads Line 724 in /public_html/sapphire/core/Object.php

Any ideas?

Avatar
Willr

Forum Moderator, 5513 Posts

30 September 2010 at 8:18pm

The error means you are printing the object out (say by using $File) and the object has no idea how to render itself. You should instead use the attributes of the object say

<% if File %>
<a href="$File.Link">$File.Title</a>
<% end_if %>

In your template.

Avatar
SamSmooth

Community Member, 18 Posts

30 September 2010 at 9:01pm

Thank you Willr!

The error occurs in the backend. Do I need to change any CMS-templates for that?

Avatar
Willr

Forum Moderator, 5513 Posts

30 September 2010 at 10:17pm

Oh right sorry, then it must have been something with your code. One issue I can see is the use of FileField as the field type. If you're in the CMS you must use one that supports ajax submissions for example FileIFrameField as the field type.

Avatar
SamSmooth

Community Member, 18 Posts

30 September 2010 at 11:08pm

Thanks again Willr.

Using FileIFrameField doesn't make a change. The error still remains:

ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'File' IN POST /admin/EditForm/field/ProductDownloads Line 724 in /public_html/sapphire/core/Object.php Source ====== 715: 716: default : 717: throw new Exception ( 718: "Object->__call(): extra method $method is invalid on $this->class:" . var_export($config, true) 719: ); 720: } 721: } else { 722: // Please do not change the exception code number below. 723: * 724: throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'", 2175); 725: } 726: } 727: 728: // ----------------------------------------------------------------------------------------------------------------- 729: 730: /** Trace =====

Object->__call(forTemplate,Array) File->forTemplate() line 447 of ViewableData.php ViewableData->XML_val(File) line 1341 of TableListField.php TableListField_Item->Fields() line 369 of ViewableData.php ViewableData->obj(Fields) line 589 of .cache.home.fsp.public_html.sapphire.templates.ComplexTableField.ss include(/tmp/silverstripe-cache-home-fsp-public_html/.cache.home.fsp.public_html.sapphire.templates.ComplexTableField.ss) line 420 of SSViewer.php SSViewer->process(ComplexTableField) line 342 of ViewableData.php ViewableData->renderWith(ComplexTableField) line 275 of ComplexTableField.php ComplexTableField->FieldHolder() line 281 of TableListField.php TableListField->index(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/ProductDownloads) line 127 of main.php

Avatar
SamSmooth

Community Member, 18 Posts

1 October 2010 at 9:02pm

This is what I get, when a file has been uploaded an I try to reopen the page:

ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'File'
IN POST /admin/getitem?ID=37&locale=en_GB&ajax=1
Line 724 in /home/fsp/public_html/sapphire/core/Object.php

Avatar
DiePlombe

Community Member, 2 Posts

7 December 2011 at 12:58pm

I have this problem too! Can anyone help?

I use Silverstripe 2.4.5 and the newest version of the DOM.

Avatar
jumprock

Community Member, 8 Posts

9 December 2011 at 3:13am

I'm having this problem also, really on a tight deadline and I've wasted hours fumbling around trying to make it work. Any developments for any of the previous posters?

Go to Top