2017 © Pedro Peláez
 

yii2-extension yii2-imagemanager

Yii2 Image Manager

image

ignatenkovnikita/yii2-imagemanager

Yii2 Image Manager

  • Thursday, February 15, 2018
  • by ignatenkovnikita
  • Repository
  • 1 Watchers
  • 0 Stars
  • 587 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 35 % Grown

The README.md

Yii2 Image Manager

Yii2 Image Manager, (*1)

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

Installation

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

Either run, (*4)

composer require --prefer-dist ignatenkovnikita/yii2-imagemanager "*"

or add, (*5)

"ignatenkovnikita/yii2-imagemanager": "*"

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

Apply migration, (*7)

php yii migrate --migrationPath=vendor/ignatenkovnikita/yii2-imagemanager/migrations/

Usage

Example use on product preview and attachments, (*8)

Add in model Product, (*9)

public $attachments;
public $attachment;

const NAME_ATTACHMENTS = 'product.attachments';
const NAME_ATTACHMENT = 'product.attachment';

public function rules()
{
    return ArrayHelper::merge(parent::rules(), [
        [['attachments', 'attachment'], 'safe'],
    ]);
}    


public function behaviors()
{
    return ArrayHelper::merge(parent::behaviors(), [
        [
            'class' => \ignatenkovnikita\imagemanager\behaviors\UploadBehavior::className(),
            'attribute' => 'attachments',
            'multiple' => true,
            'tag' => self::NAME_ATTACHMENTS,
            'pathAttribute' => 'path',
            'uploadRelation' => 'productAttachments',
            'baseUrlAttribute' => 'base_url',
            'orderAttribute' => 'order',
            'typeAttribute' => 'type',
            'sizeAttribute' => 'size',
            'nameAttribute' => 'name',
        ],
        [
            'class' => \ignatenkovnikita\imagemanager\behaviors\UploadBehavior::className(),
            'attribute' => 'attachment',
            'multiple' => false,
            'tag' => self::NAME_ATTACHMENT,
            'uploadRelation' => 'productAttachment',
            'pathAttribute' => 'path',
            'baseUrlAttribute' => 'base_url',
            'orderAttribute' => 'order',
            'typeAttribute' => 'type',
            'sizeAttribute' => 'size',
            'nameAttribute' => 'name',
        ],
    ]);
}


/**
 * @return \yii\db\ActiveQuery
 * @throws \Exception
 */
public function getProductAttachments()
{
    return $this->hasMany(ImageManager::class, ['owner_id' => 'id'])->andWhere(['tag' => self::NAME_ATTACHMENTS]);
}

/**
 * @return \yii\db\ActiveQuery
 * @throws \Exception
 */
public function getProductAttachment()
{
    return $this->hasOne(ImageManager::class, ['owner_id' => 'id'])->andWhere(['tag' => self::NAME_ATTACHMENT]);
}

Add widget on view, (*10)


field($model, 'attachment')->widget( Upload::className(), [ 'url' => ['/file-storage/upload'], 'maxFileSize' => 5000000, // 5 MiB ]); ?> field($model, 'attachments')->widget( Upload::className(), [ 'url' => ['/file-storage/upload'], 'sortable' => true, 'maxFileSize' => 10000000, // 10 MiB 'maxNumberOfFiles' => 10 ]); ?>

The Versions

15/02 2018

dev-master

9999999-dev

Yii2 Image Manager

  Sources   Download

MIT

The Requires

 

extension yii2 image imagemanager

15/02 2018

v1.1

1.1.0.0

Yii2 Image Manager

  Sources   Download

MIT

The Requires

 

extension yii2 image imagemanager

22/10 2017

v1.0

1.0.0.0

Yii2 Image Manager

  Sources   Download

MIT

The Requires

 

extension yii2 image imagemanager