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.

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

Folder field problem

Go to End

2 Posts   753 Views


Community Member, 1 Post

2 May 2012 at 8:33am

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 :)


Community Member, 116 Posts

2 May 2012 at 3:39pm

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;