21277 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1286 Views |
-
ModelAdmin Image Upload Folder

16 April 2010 at 8:14pm Last edited: 16 April 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
-
Re: ModelAdmin Image Upload Folder

18 April 2010 at 11:51pm Last edited: 18 April 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';
toprotected $folderName = 'Uploads/myImageFolder';
That helps untill the next silverstripe update. But at least it helps.
-
Re: ModelAdmin Image Upload Folder

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;
}
}
?>
| 1286 Views | ||
|
Page:
1
|
Go to Top |


