-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAvatarViewWidget.php
65 lines (56 loc) · 1.82 KB
/
AvatarViewWidget.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace daimakuai\avatar;
/**
* @see 代码块中文网 http://www.daimakuai.com
* @author yt <[email protected]>
* 设置挂件
* 如何配置请到官网(代码块中文网:www.daimakuai.com)查看相关文章
*/
use Yii;
use yii\bootstrap\Widget;
use daimakuai\avatar\assets\AvatarAsset;
use yii\base\Object;
use yii\helpers\Html;
use yii\widgets\InputWidget;
use yii\web\View;
class AvatarViewWidget extends InputWidget
{
public $options = ['class' => 'form-control'];
public $imageOptions = [];
public $inForm = false;
public $imageUrl = '';
public $setTarget = '';
public $model;
public $type = 'hidden';
public $attribute = [];
public $attributes = [];
public $view ;
public function run()
{
parent::init();
$this->view = $this->getView();
$this->attributes['id'] = $this->options['id'];
if ($this->hasModel()) {
$input = Html::activeInput($this->type, $this->model, $this->attribute, $this->attributes);
} else {
$input = Html::input($this->type, $this->name, '', $this->attributes);
}
$this->registerClientScript();
$model = new UploadForm();
echo $input;
return $this->render('view', ['model' => $model]);
}
public function registerClientScript()
{
AvatarAsset::register($this->view);
$script = "var target_tip ='".$this->options['id']."';";
$this->view->registerJs($script, View::POS_BEGIN);
$script1 = "var def_pic2 = $('#'+target_tip).val();if(def_pic2!=\"\"){ $('#pre_avatar').attr('src',def_pic2); }";
$this->view->registerJs($script1, View::POS_READY);
}
public function setFooter()
{
$model = new UploadForm();
return $this->render('upload', ['model' => $model]);
}
}