Jump to:

796 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » File Upload in Widget does not work (backend)

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 2193 Views
  • spierala
    Avatar
    Community Member
    80 Posts

    File Upload in Widget does not work (backend) Link to this post

    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

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: File Upload in Widget does not work (backend) Link to this post

    Exact same question here Help appreciated

  • swaiba
    Avatar
    Forum Moderator
    1796 Posts

    Re: File Upload in Widget does not work (backend) Link to this post

    *snip*

  • puredevotion
    Avatar
    Community Member
    4 Posts

    Re: File Upload in Widget does not work (backend) Link to this post

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

  • swaiba
    Avatar
    Forum Moderator
    1796 Posts

    Re: File Upload in Widget does not work (backend) Link to this post

    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

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