Jump to:

3430 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Just Simple DataObject with Files

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

Page: 1
Go to End
Author Topic: 2604 Views
  • nafetsch
    Avatar
    Community Member
    15 Posts

    Just Simple DataObject with Files Link to this post

    Hey Guys.

    I need a little help:. I come so far (And i done it before but lost the code )
    Here is my code:

    class DocsLinks extends DataObject {

    static $db = array(
    'FirstName' => 'Text',
    'Lastname' => 'Text',
    'Nationality' => 'Text'
    );

    static $has_one = array(
    'UnitSpec' => 'File'
    );
    function getCMSFields_forPopup() {
    $fields = new FieldSet();
    $fields->push( new TextField( 'FirstName', 'First Name' ) );
    $fields->push( new TextField( 'Lastname' ) );
    $fields->push( new TextField( 'Nationality' ) );
    $fields->push(new FileIFrameField( 'UnitSpec'));
    return $fields;
    }
    }

    AND IN THE PAGE:

       static $db = array(
          'LinksPageText' => 'text',
       );

       public static $has_one = array(
          'MyStudent' => 'DocsLinks',
          );

       public static $has_many = array(
          'UnitSpec' => 'File'
          );
    and...
             $tablefield = new HasOneComplexTableField(
             $this,
             'MyStudent',
             'DocsLinks',
             array(
                'FirstName' => 'First Name',
                'Lastname' => 'Family Name',
                'Nationality' => 'Nationality',
                'UnitSpec' => 'UnitSpec'
             ),
    'getCMSFields_forPopup'
    );

    $fields->addFieldToTab( 'Root.Content.Student', $tablefield );

    I get this Error:
    ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'fortemplate' does not exist on 'File' IN POST /admin/EditForm/field/MyStudent Line 724 in /Users/stras/Documents/Projekte/okeanosRL/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 446 of ViewableData.php ViewableData->XML_val(UnitSpec) line 1252 of TableListField.php TableListField_Item->Fields() line 369 of ViewableData.php ViewableData->obj(Fields) line 512 of .cache.Users.stras.Documents.Projekte.okeanosRL.sapphire.templates.RelationComplexTableField.ss include(/private/var/tmp/silverstripe-cache-Users-stras-Documents-Projekte-okeanosRL/.cache.Users.stras.Documents.Projekte.okeanosRL.sapphire.templates.RelationComplexTableField.ss) line 392 of SSViewer.php SSViewer->process(HasOneComplexTableField) line 342 of ViewableData.php ViewableData->renderWith(RelationComplexTableField) line 275 of ComplexTableField.php ComplexTableField->FieldHolder() line 38 of HasManyComplexTableField.php HasManyComplexTableField->FieldHolder() line 275 of TableListField.php TableListField->index(SS_HTTPRequest) line 134 of RequestHandler.php RequestHandler->handleRequest(SS_HTTPRequest) line 152 of RequestHandler.php RequestHandler->handleRequest(SS_HTTPRequest) line 152 of RequestHandler.php RequestHandler->handleRequest(SS_HTTPRequest) line 147 of Controller.php Controller->handleRequest(SS_HTTPRequest) line 283 of Director.php Director::handleRequest(SS_HTTPRequest,Session) line 127 of Director.php Director::direct(/admin/EditForm/field/MyStudent) line 127 of main.php

    Plz help, i guess its a little error...

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Just Simple DataObject with Files Link to this post

    Try removing the file field from the summary field of the table field. The file field probably doesn't have the ability to display the part to the file. So try changing your code to..

    $tablefield = new HasOneComplexTableField(
    $this,
    'MyStudent',
    'DocsLinks',
    array(
    'FirstName' => 'First Name',
    'Lastname' => 'Family Name',
    'Nationality' => 'Nationality'
    ),

    The file field will still be in the popup, just not in the summary.

  • nafetsch
    Avatar
    Community Member
    15 Posts

    Re: Just Simple DataObject with Files Link to this post

    oh cool! thx´s for your reply!

    I don´t get an error anymore. but the file will NOT upload. I see the upload field and when i choose my file, the file don´t show up in the popup or in the database.

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