Jump to:

23355 Posts in 17838 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » ModelAdmin Image Upload Folder

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: 1561 Views
  • joko
    Avatar
    Community Member
    6 Posts

    ModelAdmin Image Upload Folder Link to this post

    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

  • joko
    Avatar
    Community Member
    6 Posts

    Re: ModelAdmin Image Upload Folder Link to this post

    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.

  • mawk
    Avatar
    Community Member
    4 Posts

    Re: ModelAdmin Image Upload Folder Link to this post

    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;
    }
    }
    ?>

    1561 Views
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.