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.

Customising the CMS /

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

Modify FileField


Go to End


19 Posts   4691 Views

Avatar
JuLo

Community Member, 37 Posts

3 December 2009 at 6:12am

Hi,

I'd like to modify FileField (or create a new type of field) so it can accept a folder instead of only files.

(I basically just want to have a browse button and save the path that I pointed to)

Can anyone point me into the right direction?

Thanks

Julien

Avatar
bummzack

Community Member, 904 Posts

3 December 2009 at 10:24am

I don't quite understand what you're trying to do.
Do you want to select a folder on your local computer and store the path to that folder?
Or do you want to be able to select a folder on the server (from the assets folder)?

Avatar
JuLo

Community Member, 37 Posts

3 December 2009 at 12:22pm

A folder on the server.

I've created a sort of slideshow in Flash and would like to be able to pass a path to it (through a php) to tell it which folder to get its pictures from.

Thanks in advance for your help.

Avatar
ajshort

Community Member, 244 Posts

3 December 2009 at 5:14pm

You can just use TreeDropdownField with a DataObjectSet of all the folders. Something like "new TreeDropdownField('Folder', 'Select a Folder', 'Folder')" should do the job.

Avatar
JuLo

Community Member, 37 Posts

4 December 2009 at 1:17pm

Oh OK. That seems simple enough.

I'll give that a shot.
Thanks

Avatar
JuLo

Community Member, 37 Posts

8 December 2009 at 8:24pm

Edited: 08/12/2009 9:07pm

Ok.
I tried it by including this in my pages getCMSfields
$fields->addFieldToTab("Root.Content.Banner", new TreeDropdownField("FolderForBanner", "Choose a folder to get the images for the slideshow from", "Folder"));

It seems to work.

But I don't know how to use the selected path in the .ss Page.
If I just put $FolderForBanner in the ss file, it obviously cannot work.
How to turn this "path object" into a string?

Some more help please?

Thanks.

Avatar
Fuzz10

Community Member, 791 Posts

8 December 2009 at 11:38pm


First get the folder-object in your code .... And feed that to your template :

$tmpFolder = DataObject::get_by_id("Folder",$FolderForBannerID);
return $tmpFolder

Avatar
ajshort

Community Member, 244 Posts

9 December 2009 at 12:21am

Actually that is completely unnecessary. You can just access a $has_one relationship in your template by using $HasOneName. You then can do $HasOneName.URL or $HasOneName.RelativePath or whatever in your template.

Go to Top