I use yii2, yii2-gallery-manager
Created a controller
class GalleryImageController extends \yii\web\Controller { public function actions() { return [ 'galleryApi' => [ 'class' => GalleryManagerAction::className(), // mappings between type names and model classes (should be the same as in behaviour) 'types' => [ 'portfolio' => GalleryImage::className() ] ], ]; } public function actionIndex() { $dataProvider = GalleryImage::find()->all(); return $this->render('index', ['model' => $dataProvider[0]]); } } Model
class GalleryImage extends \yii\db\ActiveRecord { public static function tableName() { return 'gallery_image'; } public function rules() { return [ [['type', 'ownerId', 'name', 'description'], 'required'], [['type', 'ownerId', 'name', 'description'], 'string'], [['rank'], 'integer'], ]; } public function behaviors() { return [ 'galleryBehavior' => [ 'class' => GalleryBehavior::className(), 'type' => 'portfolio', 'extension' => 'jpg', 'directory' => '/images/gallery', 'url' => '/images/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); }, ] ] ]; } public function attributeLabels() { return [ 'id' => 'ID', 'type' => 'Type', 'ownerId' => 'Owner ID', 'rank' => 'Rank', 'name' => 'Name', 'description' => 'Description', ]; } } Vyyuschke take out
<div class="row"> <div class="col-xs-12 text-center"> <div class="panel panel-default"> <div class="panel-heading">Галерея "Фото"</div> <div class="panel-body"> <?php if ($model->isNewRecord) { echo 'Can not upload images for new record'; } else { echo GalleryManager::widget( [ 'model' => $model, 'behaviorName' => 'galleryBehavior', 'apiRoute' => 'portfolio/galleryApi' ] ); } ?> </div> </div> </div> </div> The folder with pictures lies in web folders in both backend and frontend. In the database 1 entry
- id - 1
- type - jpg
- ownerid - 3
- rank - 10
- name - maxresdefault.jpg
- description - maxresdefault.jpg
how to be?