/
FileUpload.php
executable file
·51 lines (37 loc) · 1.23 KB
/
FileUpload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace pipekung\widgets;
use kartik\widgets\FileInput;
use yii\helpers\Html;
/**
* Description of FileUpload
*
* @author ksorn <ksorn@kku.ac.th>
* @since 2.0
*/
class FileUpload extends Widget {
public $model;
public $form;
public $name;
public $attr;
public $data;
public $options;
protected $label;
public function init() {
parent::init();
$this->label = $this->model->getAttributeLabel($this->attr);
}
public function run() {
echo $this->form->field($this->model, $this->attr)->widget(FileInput::classname(), [
'options' => ['accept' => ''],
'pluginOptions' => [
'showPreview' => false,
'showCaption' => true,
'showRemove' => true,
'showUpload' => false,
]
]);
if( $this->model->getAttribute($this->attr) !== null){
echo '<div class="file-upload-update"><label class="col-sm-2"> </label>' .Html::a($this->model->getAttribute($this->attr), ['/uploads/'.$this->model->getAttribute($this->attr)]). '</div>';
}
}
}