php - How to add many files with silverstripe uploadfield -
hello everyone,
i'm trying add more 1 file uploadfield 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 make clear: i'm trying add documentfile in documentpageacces1. when execute code, have in documentpageacces1 tab documentsfiles , in tab have uploadfield.
the problem uploadfield doesn't want keep file when chose file, click ok in finder , nothing happens......could me?
thanks thomas.
uploadfield
isn't made work dataobjects
found file
or it's subclasses.
although in case, don't think need subclass, remove documentfiledo
class extend file
, use in documentpageacces1.php
static $has_many = array( 'documentfiles' => 'file', );
in case want have more control/details on files upload (i.e. add descriptions, titles etc...), in case can create dataobject
has $has_one relation file
, use dataobject
in relation on page gridfield
:
documentfile.php
class documentfile extend dataobject { static $db = array( 'description' => 'htmltext' ); static $has_one = array( 'file' => 'file' ); }
documentpageacces1.php
static $has_many = array( 'documentfiles' => 'documentfile' ); function getcmsfields() { $fields = parent::getcmsfields(); $c = new gridfieldconfig_relationeditor(); $f = new gridfield('documents', 'documentfiles', $this->documentfiles(), $c); $fields->addfieldtotab('root.documents', $f); return $fields; }
Comments
Post a Comment