Jump to:

23477 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Folder field problem

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: 392 Views
  • Ragnarock
    Community Member
    1 Post

    Folder field problem Link to this post

    Hi guys,

    I'm experiencing a problem with creating a field (for a Page type class) to select a folder from assets (e.g. gallery).
    As I've read and looked up in a module (ImageGallery basic) to make such a field one should use TreeDropdownField.
    But when it comes to the real deal - the dropdown shows "loading..." and error pops up "Error getting data".
    This is the implementation i used (folder option in ImageGallery basic is not working for me as well):

    class TestPage extends Page {
    static $db = array();

       static $has_one = array(
          "SourceFolder" => "Folder"
       function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab("Root.Content.Main", new TreeDropdownField("SourceFolderID", "Source Folder", "Folder"));

    return $fields;

    Using version 2.4.7.
    Thanks in advance. I'll be contributing some useful modules/widgets if you help me on this

  • novaweb
    Community Member
    115 Posts

    Re: Folder field problem Link to this post

    Hi Ragna,

    I'm not too familiar with Treedropdownfield, but....

    This is from the Treedropdown file:

        * @param sourceObject The object-type to list in the tree. Must be a 'hierachy' object. Alternatively,
        * you can set this to an array of key/value pairs, like a dropdown source. In this case, the field
        * will act like show a flat list of tree items, without any hierachy.

    (Just got a text to leave work so will have to be quick)

    $folder = DataObject::get('File', ClassName = 'Folder'); // and any other parameters you may need

    function getCMSFields(){
    $fields = parent::getCMSFields();

    $fields->addFieldToTab("Root.Content.Main", new TreeDropdownField("SourceFolderID", "Source Folder", $folder));

    return $fields;


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.