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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Just Simple DataObject with Files


Go to End


3 Posts   3943 Views

Avatar
nafetsch

Community Member, 15 Posts

6 August 2010 at 8:39pm

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...

Avatar
Willr

Forum Moderator, 5523 Posts

7 August 2010 at 11:36am

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.

Avatar
nafetsch

Community Member, 15 Posts

9 August 2010 at 7:04pm

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.