金叶网 / yii2-avatar
yii2-avatar
dev-master
2021-02-24 08:33 UTC
Requires
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-09-24 17:01:09 UTC
README
yii2-avatar
安装
安装此扩展的首选方式是通过 composer。
运行
php composer.phar require --prefer-dist xinyeweb/yii2-avatar "dev-master"
或在您的 composer.json
文件的 require 部分添加
"xinyeweb/yii2-avatar": "dev-master"
to the require section of your composer.json
file.
使用方法
扩展安装完成后,只需在代码中使用即可
//在当前控制器的actions中添加如下配置 public function actions() { return [ 'crop'=>[ 'class' => 'daimakuai\avatar\CropAction', 'config'=>[ 'bigImageWidth' => '200', //大图默认宽度 'bigImageHeight' => '200', //大图默认高度 'middleImageWidth'=> '100', //中图默认宽度 'middleImageHeight'=> '100', //中图图默认高度 'smallImageWidth' => '50', //小图默认宽度 'smallImageHeight' => '50', //小图默认高度 //头像上传目录(注:目录前不能加"/") 'uploadPath' => 'uploads/avatar', ] ] ]; } //调用方式,imageUrl为默认图地址 <?= \xinyeweb\avatar\AvatarWidget::widget(['imageUrl'=>'/statics/images/avatar/avatar.jpg']); ?>
在form表单中使用 <?= $form->field($model, 'avatar')->widget(\xinyeweb\avatar\AvatarViewWidget::className()) ?> 在form的界面添加上传组件 <?php $obj = new \xinyeweb\avatar\AvatarUploadWidget(['imageUrl'=>'/statics/images/avatar/avatar.jpg']);echo $obj->setFooter(); ?>