xtracode/yii2-image
Composer 安装命令:
composer require xtracode/yii2-image
包简介
Yii2 image module
关键字:
README 文档
README
Yii2 module for image manipulating.
Documentation is at docs/guide/README.md.
Features
- image upload
- display image widget
- watermark (text and image)
- image resize on demand
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require "xtracode/yii2-image" "dev-master"
or add
"xtracode/yii2-image" : "dev-master"
to the require section of your application's composer.json file.
Configuration
- Add module to config section:
'modules' => [ 'image' => [ 'class' => 'xtracode\yii2-image\ImageModule' ] ]
- Run migrations:
php yii migrate --migrationPath=@xtracode/yii2-image/migrations
Usage
- Add actions to your controller:
public function actions() { return [ 'delete-image' => [ 'class' => '\xtracode\image\actions\DeleteImageAction', ], 'main-image' => [ 'class' => '\xtracode\image\actions\MainImageAction', ], ]; }
Upload multiple image
Use method $model->uploadSingleImage() in controller:
public function actionCreate() { $model = new Article; if ($model->load($_POST) && $model->save()) { $model->uploadImage(); \Yii::$app->session->setFlash('success', \Yii::t('article', 'Article successfully saved')); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } }
In view:
<div class="col-sm-offset-1"> <?= \xtracode\image\widgets\ImageList::widget([ 'model' => $model, 'model_id' => $model->id, ]) ?> </div>
Upload single image
use method $model->uploadSingleImage() in controller:
public function actionCreate() { $model = new Article; if ($model->load($_POST) && $model->save()) { $model->uploadSingleImage(); \Yii::$app->session->setFlash('success', \Yii::t('article', 'Article successfully saved')); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } }
In view:
<div class="col-sm-offset-1"> <?= \xtracode\image\widgets\ImageList::widget([ 'model' => $model, 'model_id' => $model->id, ]) ?> </div>
For more details see the guide.
统计信息
- 总下载量: 302
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-08-28