2017-25 © Pedro Peláez
 

library yii2-avatar

yii2 upload avatar widget

image

opqnext/yii2-avatar

yii2 upload avatar widget

  • Friday, April 20, 2018
  • by opqnext
  • Repository
  • 1 Watchers
  • 2 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 90 % Grown

The README.md

yii2-avatar, (*1)

教程

这是一款基于 Yii2.0 的上传头像小部件。, (*2)

这个小部件怎么用呢?, (*3)

  1. 安装
composer require "opqnext/yii2-avatar:dev-master"
  1. 使用

在试图文件的头像展示位添加以下内容:, (*4)

// imageUrl 是当前用户头像地址(当前未上传头像则为默认图片)
<?= \opqnext\avatar\AvatarWidget::widget(['imageUrl'=>'https://image.opqnext.com/logo.jpg'])?>

如果样式有偏差,可以使用如下代码微调样式:, (*5)

<?php
$cssString = ".modal-dialog{left:auto;width:900px;}";
$this->registerCss($cssString);
?>

点击确定小部件会提交form表单,提交地址为 actionAvatar 所以需要在该控制器添加此方法。, (*6)

方法内容如下:, (*7)

public function actionAvatar()
{
    \Yii::$app->response->format=Response::FORMAT_JSON;

    // 注意按需分配图片上传地址。
    $clip = new ClipUploadAvatar(
        isset($_POST['avatar_src']) ? $_POST['avatar_src'] : null,
        isset($_POST['avatar_data']) ? $_POST['avatar_data'] : null,
        isset($_FILES['avatar_file']) ? $_FILES['avatar_file'] : null,
        \Yii::getAlias('@webroot').'/img/avatar'
    );
    $response = array(
        'state'  => 200,
        'message' => $clip->getMsg(),
        'result' => \Yii::getAlias('@web').'/img/avatar/'.$clip->getResult()
    );

    // ...存储数据库等

    return $response;
}

如有问题,欢迎加入 QQ群:452209691 共同探讨。, (*8)

参考内容:https://github.com/org-yii-china/yii2-avatar, (*9)

The Versions

20/04 2018

dev-master

9999999-dev

yii2 upload avatar widget

  Sources   Download

MIT

The Requires

 

by Avatar opqnext

php yii2 avatar

20/04 2018

v1.0

1.0.0.0

yii2 upload avatar widget

  Sources   Download

MIT

The Requires

 

by Avatar opqnext

php yii2 avatar