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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

How to add many files with silverstripe uploadfield


Go to End
Reply


412 Views

Avatar
JonnyCash

Community Member, 4 Posts

25 July 2013 at 10:45pm

**Hello everyone**,

I'm trying to add more than 1 file to my uploadfield with this code ->

class FileDo extends File {

static $has_one = array(
'DocumentsFile' => 'DocumentsFile',

);
}

class DocumentsFile extends DataObject {

static $has_one = array(
'DocumentPageAcces1' => 'DocumentPageAcces1'
);
static $has_many = array(
'Files' => 'FileDo'
);

public function getCMSFields() {
$fields = parent::getCMSFields();

$fields->removeByName('DocumentPageAcces1ID');

return $fields;
}

public function onBeforeWrite() {
parent::onBeforeWrite();
$page = DataObject::get_one('DocumentPageAcces1');
if($page) {
$this->DocumentPageAcces1ID = $page->ID;
}
}

}

class DocumentPageAcces1 extends Page {

static $has_many = array(
'DocumentsFiles' => 'DocumentsFile',
);

public function getCMSFields() {

$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Main', new TextareaField('DocumentsIntro_en', "Document Introduction"));
$fields->addFieldToTab('Root.Main', new TextareaField('PublicationsIntro_en', "Publication Introduction"));

$fields->addFieldToTab('Root.FR', new TextareaField('DocumentsIntro_fr', "Document Introduction"));
$fields->addFieldToTab('Root.FR', new TextareaField('PublicationsIntro_fr', "Publication Introduction"));

$fields->addFieldToTab('Root.NL', new TextareaField('DocumentsIntro_nl', "Document Introduction"));
$fields->addFieldToTab('Root.NL', new TextareaField('PublicationsIntro_nl', "Publication Introduction"));

$upload = new UploadField(
'DocumentsFile',
'Document',
$this->DocumentsFiles()
);

$fields->addFieldToTab('Root.DocumentsFile', $upload);

$fields->removeByName('Content');
$fields->removeByName('Metadata');

return $fields;
}

}
class DocumentPageAcces1_Controller extends Page_Controller {

}

So to make it clear: i'm trying to add some DocumentFile in my DocumentPageAcces1. When i execute this code, i have in my DocumentPageAcces1 the tab DocumentsFiles and in this tab i have the uploadfield.

THE PROBLEM is that the uploadfield doesn't want to keep my file so when i chose some file, i click OK in my finder and nothing happens......Could anyone help me?

Thanks Thomas.