dev-master
9999999-devPort of 'zxbodya/yii-gallery-manager'. Extension for yii, that allows to manage image galleries
MIT
The Requires
by Bogdan Savluk
by Alexander Shchukin
extension yii2 gallery image
Port of 'zxbodya/yii-gallery-manager'. Extension for yii, that allows to manage image galleries
Yii2 port of https://github.com/zxbodya/yii-gallery-manager, (*1)
warning: preview version, (*2)
php composer.phar require --prefer-dist sashsvamir/yii2-gallery-manager "*@dev"
, (*3)
Add migration to create table for images:, (*4)
class m150318_154933_gallery_ext extends \sashsvamir\galleryManager\migrations\m140930_003227_gallery_manager { }
Or better - copy migration to your application., (*5)
Add GalleryBehavior to your model, and configure it, create folder for uploaded files., (*6)
public function behaviors() { return [ 'galleryBehavior' => [ 'class' => GalleryBehavior::class, '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., (*7)
public function actions() { return [ 'galleryApi' => [ 'class' => GalleryManagerAction::class, // mappings between type names and model classes (should be the same as in behaviour) 'types' => [ 'product' => Product::class ] ], ]; }
Add ImageAttachmentWidget somewhere in you application, for example in editing from., (*8)
echo sashsvamir\galleryManager\GalleryManager::widget([ 'model' => $model, 'behaviorName' => 'galleryBehavior', 'apiRoute' => 'product/galleryApi', 'options' => [ 'class' => 'form-group', ], ]);
Done!, (*9)
Now, you can use uploaded images from gallery like following:, (*10)
foreach($model->getBehavior('galleryBehavior')->getImages() as $image) { echo Html::img($image->getUrl('medium')); }
{{%gallery_image}}
):tableName
property in behavior configurationPort of 'zxbodya/yii-gallery-manager'. Extension for yii, that allows to manage image galleries
MIT
extension yii2 gallery image