2017 © Pedro Peláez
 

yii2-extension yii2-image

Yii2 image module

image

xtracode/yii2-image

Yii2 image module

  • Thursday, August 10, 2017
  • by xtracode
  • Repository
  • 1 Watchers
  • 0 Stars
  • 155 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Image Module for Yii2

License Latest Stable Version Latest Unstable Version Total Downloads, (*1)

Yii2 module for image manipulating., (*2)

Documentation is at docs/guide/README.md., (*3)

Features

  • [x] image upload
  • [x] display image widget
  • [ ] watermark (text and image)
  • [x] image resize on demand

Installation

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

Either run, (*5)

php composer.phar require "xtracode/yii2-image" "dev-master"

or add, (*6)

"xtracode/yii2-image" : "dev-master"

to the require section of your application's composer.json file., (*7)

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:, (*8)

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:, (*9)

<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:, (*10)

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:, (*11)

<div class="col-sm-offset-1">
    <?= \xtracode\image\widgets\ImageList::widget([
        'model' => $model,
        'model_id' => $model->id,
    ]) ?>
</div>

For more details see the guide., (*12)

The Versions

10/08 2017