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, biapar, Willr, Ingo, swaiba, simon_w

ModelAdmin Image Upload Folder


Reply


3 Posts   1627 Views

Avatar
joko

Community Member, 6 Posts

16 April 2010 at 8:14pm

Edited: 16/04/2010 8:15pm

Hi,

there has been a problem uploading images using ImageField which seemed to be resolved in 2.4 (http://www.silverstripe.org/general-questions/show/257307#post257307 and http://www.silverstripe.org/customising-the-cms/show/276189#post276189").

I still struggle with changing the upload folder when I use the scaffolded upload of a subclass of ModelAdmin. Since I do not implement an ImageField, the workaround is not working and my 'upload'-folder is overflowing.

How can I change the default upload location in ModelAdmin in combination with $has_one Image?

cheers

joko

Avatar
joko

Community Member, 6 Posts

18 April 2010 at 11:51pm

Edited: 18/04/2010 11:52pm

Well, I found a q&d-workaround: open the file sapphire/forms/filefield.php and edit line 66 from

protected $folderName = 'Uploads';


to

protected $folderName = 'Uploads/myImageFolder';

That helps untill the next silverstripe update. But at least it helps.

Avatar
mawk

Community Member, 4 Posts

24 June 2012 at 6:11am

I was able to get it working by setting the image upload folder using the getCMSFields() method. Here's what I've got.

<?php
//the class that defines the top level tab
class MyNewSection extends ModelAdmin {

public static $managed_models = array( //since 2.3.2
'MyModelName'
);

static $url_segment = 'mytaburl'; // will be linked as /admin/products
static $menu_title = 'My Model Items';

}

class MyModelName extends DataObject {
static $db = array(
'Title' => 'Text'
);

static $has_one = array(
"Image" => "Image"
);

static $searchable_fields = array(
'Title'
);

function getCMSFields() {
$fields = parent::getCMSFields();
$lField = new ImageField("Image", "My Model Photo");
$lField->setFolderName("Uploads/MySpecificFolder");

$fields->addFieldToTab("Root.Main", $lField);
return $fields;
}
}
?>