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.

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

Image Relationship


Go to End


749 Views

Avatar
clauddiu

Community Member, 5 Posts

19 July 2012 at 8:44pm

Edited: 19/07/2012 8:47pm

Hello,

I have this code where I have to upload some data and a file, the data is showing when I parse it but not the file.. this is my code, if anyone can please tell me what I do wrong I will really apreciate it.

Homepage.php

<?php

class HomePage extends SiteTree {    

}

class HomePage_Controller extends Page_Controller {

    public function init() {
        parent::init();
    }


    public function SubmitForm() {
        $form = new Form (
            $this,
            "SubmitForm",
            new FieldList (
                new DropdownField('Workspace', _t('UploadItem.WORKSPACE','Workspace'), singleton('UploadItem')->dbObject('Workspace')->enumValues()),
                new TextareaField('Description', _t('UploadItem.DESCRIPTION','Description')),
                new UploadField('uFiles', _t('UploadItem.UFILES','Upload File'))
            ),
            new FieldList (
                new FormAction('doApply', _t('UploadItem.APPLYNOW','Save'))
            )
            //, new RequiredFields('Description','UploadFile')
        );

        return $form;
    }

    public function doApply($data, $form) {
        $submission = new UploadItem();
        $form->saveInto($submission);
        $submission->write();
        return $this->redirectBack();
    }

    public function showFiles() {
        return  UploadItem::get();
    }

}

UploadItem.php


<?php

class UploadItem extends DataObject {
    static $db = array(
        'Description' => 'Text',
        'Workspace' => "Enum('First Project,  Second Project, Other Project')"
    );

    static $has_one = array(
       	'uFiles' => 'File'
    );
}

Homepage.ss

<ul>
	<% loop showFiles %>
	<li>Description: $Description in  $Workspace, File <br />
		Link: $uFiles.Link <br />
		Filename: $uFiles.Name <br />
		URL: $uFiles.URL </br />


	</li>
	<% end_loop %>
</ul>

I try to make this work for like 2 days, please guys give me a hint.

Thank you,
Claudiu