This widget is a Yii 2 wrapper of FileAPI plugin., (*1)
this is an adapt for sina app engine, (*2)
this is based on https://github.com/vova07/yii2-fileapi-widget, (*3)
Installation
The preferred way to install this extension is through composer., (*4)
Either run, (*5)
php composer.phar require --prefer-dist "postor/yii2-fileapi-sae" "*"
or add, (*6)
"postor/yii2-fileapi-sae": "*"
to the require section of your composer.json
file., (*7)
Usage:
// MyController.php
use postor\fileapi\actions\UploadAction as FileAPIUpload;
...
public function actions()
{
return [
'fileapi-upload' => [
'class' => FileAPIUpload::className(),
'path' => 'saestor://upload/temp'
]
];
}
// MyModel.php
use postor\fileapi\behaviors\UploadBehavior;
...
public function behaviors()
{
return [
'uploadBehavior' => [
'class' => UploadBehavior::className(),
'attributes' => [
'preview_url' => [
'path' => 'saestor://upload/temp',
'tempPath' => 'saestor://upload/category',
'url' => $saeStorage->getUrl('upload','category'),
],
]
]
];
}
// _form.php
use postor\fileapi\Widget as FileAPI;
...
echo $form->field($model, 'preview_url')->widget(
FileAPI::className(),
[
'settings' => [
'url' => ['/controller/fileapi-upload']
]
]
);
demo project: http://yii2postor.sinaapp.com/web/index.php?r=admin%2Fcategory%2Fupdate&id=2, (*8)