Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Unable to display uploaded files

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

Page: 1 2
Go to End
Author Topic: 2523 Views
  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Unable to display uploaded files Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Unable to display uploaded files Link to this post

    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.

  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Re: Unable to display uploaded files Link to this post

    Thank you Willr!

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

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: Unable to display uploaded files Link to this post

    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.

  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Re: Unable to display uploaded files Link to this post

    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

  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Re: Unable to display uploaded files Link to this post

    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

  • DiePlombe
    Avatar
    Community Member
    2 Posts

    Re: Unable to display uploaded files Link to this post

    I have this problem too! Can anyone help?

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

  • jumprock
    Avatar
    Community Member
    8 Posts

    Re: Unable to display uploaded files Link to this post

    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?

    2523 Views
Page: 1 2
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.