dev-master
9999999-devExtension for yii, that allows to manage image galleries
MIT
The Requires
by Bogdan Savluk
extension yii2 gallery image
Extension for yii, that allows to manage image galleries
Yii2 port of https://github.com/iswebjscom/yii2-gallery-manager.git, (*1)
(frontend part mostly without changes, but backend was rewritten almost completely), (*2)
Gallery manager screenshots (yii 1.x version, new one has bootstrap 3 styles):, (*3)
, (*4)
Few more screenshots: drag & drop upload, editing image information, upload progress,, (*5)
The preferred way to install this extension is through composer., (*6)
Either run, (*7)
composer require apolle/yii2-gallery-manager
, (*8)
or add, (*9)
apolle/yii2-gallery-manager
, (*10)
to the require section of your composer.json
file., (*11)
Add migration to create table for images:, (*12)
class m150318_154933_gallery_ext extends zxbodya\yii2\galleryManager\migrations\m140930_003227_gallery_manager { }
Or better - copy migration to you application(but be sure to remove namespace from it - it should be in global namespace), (*13)
Add GalleryBehavior to your model, and configure it, create folder for uploaded files., (*14)
public function behaviors() { return [ 'galleryBehavior' => [ 'class' => GalleryBehavior::className(), 'type' => 'product', 'extension' => 'jpg', 'directory' => Yii::getAlias('@webroot') . '/images/product/gallery', 'url' => Yii::getAlias('@web') . '/images/product/gallery', 'versions' => [ 'small' => function ($img) { /** @var \Imagine\Image\ImageInterface $img */ return $img ->copy() ->thumbnail(new \Imagine\Image\Box(200, 200)); }, 'medium' => function ($img) { /** @var Imagine\Image\ImageInterface $img */ $dstSize = $img->getSize(); $maxWidth = 800; if ($dstSize->getWidth() > $maxWidth) { $dstSize = $dstSize->widen($maxWidth); } return $img ->copy() ->resize($dstSize); }, ] ] ]; }
Add GalleryManagerAction in controller somewhere in your application. Also on this step you can add some security checks for this action., (*15)
public function actions() { return [ 'galleryApi' => [ 'class' => GalleryManagerAction::className(), // mappings between type names and model classes (should be the same as in behaviour) 'types' => [ 'product' => Product::className() ] ], ]; }
Add ImageAttachmentWidget somewhere in you application, for example in editing from., (*16)
if ($model->isNewRecord) { echo 'Can not upload images for new record'; } else { echo GalleryManager::widget( [ 'model' => $model, 'behaviorName' => 'galleryBehavior', 'apiRoute' => 'product/galleryApi' ] ); }
Done!, (*17)
Now, you can use uploaded images from gallery like following:, (*18)
foreach($model->getBehavior('galleryBehavior')->getImages() as $image) { echo Html::img($image->getUrl('medium')); }
{{%gallery_image}}
):tableName
property in behavior configurationExtension for yii, that allows to manage image galleries
MIT
extension yii2 gallery image