How to use file upload in agile toolkit 4.2

2019-07-31 10:15发布

问题:

Is there somewhere a full example of working atk4.2 filestore example code?

I've been searching in docs and stackoverflow and the few examples I have found just aren't working for me.

Do I need to extend Model_File or Model_Filestore_File ?

First gives me error

Class is not defined in file

Second one gives

Unable to include filestore/lib/Model/Filestore/File.php

What would be the simplest way to add file upload to CRUD?

回答1:

If you want to have file upload, use the following in your model:

$this->add('filestore/Field_File','file_id');

the field should reference filestore_file.id. If you are looking to have a image upload with thumbnail, then:

$this->add('filestore/Field_Image','picture_id');

Once image is uploaded and form is submitted, the "id" of the file will be in respective field. For Field_Image it will also resize the thumbnail. You can further customize this by using your own image model:

    ->setModel('MyImage');

class Model_MyImage extends filestore\Model_Image {
    public $default_thumb_width=32;
    public $default_thumb_height=32;
}

This should work fine with 4.2.0, but the "development" branch is currently having some refinements which would allow to have multiple thumbnail sizes per image.