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.

Widgets /

Discuss SilverStripe Widgets.

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

File Upload in Widget does not work (backend)


Reply


5 Posts   2228 Views

Avatar
spierala

Community Member, 80 Posts

8 February 2010 at 10:42am

Hello all,

I want to create a widget. The widget has the possibility to upload an image in the backend area. In the frontend the widget just outputs the image. Basically the widget works fine. But somehow the File Upload never works. The widgets appear in the database, but they always get FileId 0. If I set the FileId in the database to a proper/existing value the outputted site looks perfect.

Thats my code:

<?php
class StandardTeaser extends Widget {
   static $title = "Neuer Standard-Teaser";
   static $cmsTitle = "Neuer Standard-Teaser";
   static $description = "Neuen Standard-Teaser anlegen";
   
   static $db = array(
      'Header' => 'Text'
   );
   
   static $has_one = array(
      'File' => 'File'
   );
   
   function getCMSFields() {
      $fields = new FieldSet();
      $fields->push( new TextField('Header'));
      $fields->push( new FileField('File'));
      return $fields;
   }
}
?>

if I use ImageField instead of FileField then the backend does not even appear.
Is there something special with file uploads in widgets?

thanks so much,
florian

Avatar
klikhier

Community Member, 150 Posts

20 April 2010 at 8:23am

Exact same question here :) Help appreciated

Avatar
swaiba

Forum Moderator, 1799 Posts

13 August 2010 at 7:17am

Edited: 17/08/2010 2:58am

*snip*

Avatar
puredevotion

Community Member, 4 Posts

14 August 2010 at 12:51am

I don't have a direct solution for you, and I've never made any widgets before(nor have used them)

but why don't you check how they did it in cms\code\AssetAdmin.php (better yet, extend that class, if that's possible with widgets)
They handle all uploading, moving and storing. Create a new function that saves all your banners/images/slides into a database table, and extract that then into the front-end.

I'm subscribed and following this, as I was planning to write something on my own. However, I first need to complete my bizz-website before I can go experimenting.

Hope this helps a bit...

Avatar
swaiba

Forum Moderator, 1799 Posts

17 August 2010 at 3:01am

Well I have finished my code and it is a bit simpler that I'd imagined and works!

I did notice that this was about files in the backend so I've removed the code I have and instead I'll link over to the post with the image solution... to do the same thing with files should be fairly easy (just change what is shown instead of an image thumb).

an image solution...
http://www.silverstripe.org/widgets-2/show/267667?start=0#post290372

Barry