Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » How to add many files with silverstripe uploadfield

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

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

Page: 1
Go to End
Author Topic: 150 Views
  • JonnyCash
    Avatar
    Community Member
    4 Posts

    How to add many files with silverstripe uploadfield Link to this post

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

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