2017 © Pedro Peláez
 

yii2-extension yii2-qiniu-upload-widget

这是一个七牛js小部件

image

xyb/yii2-qiniu-upload-widget

这是一个七牛js小部件

  • Sunday, September 25, 2016
  • by smartyPHP
  • Repository
  • 2 Watchers
  • 7 Stars
  • 39 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

七牛jssdk组件的yii2部件

用于上传到七牛的小部件, (*1)

安装

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist xyb/yii2-qiniu-upload-widget "dev-master"

or add, (*4)

"xyb/yii2-qiniu-upload-widget": "dev-master"

to the require section of your composer.json file., (*5)

基本用法

使用如下:, (*6)

js参数和七牛的jssdk参数一致,使用数组方式传递, (*7)

1.在view视图输出,domain参数要填好,也就是的上传目的地址, (*8)

<?= \xyb\qiniu\Qiniu::widget([
    'name' => 'name',
    'id' => 'id',
    'jsOptions' => [
        'domain' => 'http://static.xxx.net/',   // 最后反斜杠不要忘了
    ]
]) ?>

2.加载uploadToken的action,默认路由是/site/tokenAction,eg:在siteController的actions方法添加,action的参数必须填写好七牛的accessKey,secretKey,bucker,domain, (*9)

public function actions()
{
    return [
        'error' => [
            'class' => 'yii\web\ErrorAction',
        ],
        'captcha' => [
            'class' => 'yii\captcha\CaptchaAction',
            'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
        ],
        'tokenAction' => [
            'class' => 'xyb\qiniu\TokenAction',
            'ak' => Yii::$app->params['qiniu']['ak'],
            'sk' => Yii::$app->params['qiniu']['sk'],
            'domain' => Yii::$app->params['qiniu']['domain'],
            'bucket' => Yii::$app->params['qiniu']['bucket']
        ],
    ];
}

额外用法

可以传递自定义的html作为上传组件的界面,定义containerId和browseButtonId只需要在节点定义,如 <div id='{!!containerId!!}'><button id='{!!browseButtonId!!}'></button></div> 其中,{!!containerId!!}会动态解析为基于组件传递的id的containerId,{!!browseButtonId!!}亦同理,更多请参考源码注释, (*10)

The Versions

25/09 2016

dev-master

9999999-dev

这是一个七牛js小部件

  Sources   Download

Apache-2.0

The Requires

 

by 肖永标

extension yii2