PHP code example of resmedia / yii2-mongo-gallery-manager

1. Go to this page and download the library: Download resmedia/yii2-mongo-gallery-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

resmedia / yii2-mongo-gallery-manager example snippets


GalleryManager::widget([
    'model' => $model,
    'behaviorName' => 'galleryBehavior',
    'apiRoute' => 'galleryApi'
])

$actions['galleryApi'] = [
   'class' => GalleryManagerAction::class,
   'types' => [
       'news' => News::class
   ]
];

$behaviors['access']['rules'] = [
      [
           'actions' => [
                    ......, 'galleryApi',
           ],
           'allow' => true,
           'roles' => ['@'],
      ],
];

class NewsController extends Controller
{
...
public function actions()
{
    return [
       'galleryApi' => [
           'class' => GalleryManagerAction::class,
           // mappings between type names and model classes (should be the same as in behaviour)
           'types' => [
               'news' => News::class
           ]
       ],
    ];
}

'galleryBehavior' => [
       'class' => GalleryBehavior::class,
       'type' => 'news',
       'extension' => 'jpg',
       // image dimmentions for preview in widget
       'previewWidth' => 300,
       'previewHeight' => 200,
       // path to location where to save images
       'directory' => Yii::getAlias('@api') . '/web/bucket/items',
          'url' => Yii::$app->params['domainFrontend'] . '/bucket/items',
          // additional image versions
          'versions' => [
              'original' => function ($img) {
                  $width = 1000;
                  $height = 550;
                  return $img
                      ->copy()
                      ->thumbnail(new Box($width, $height), ImageInterface::THUMBNAIL_OUTBOUND);
              },
              'medium' => function ($img) {
                  $width = 600;
                  $height = 328;
                  return $img
                      ->copy()
                      ->thumbnail(new Box($width, $height), ImageInterface::THUMBNAIL_OUTBOUND);
              },
              'preview' => function ($img) {
                  $width = 300;
                  $height = 164;
                  return $img
                      ->copy()
                      ->thumbnail(new Box($width, $height), ImageInterface::THUMBNAIL_OUTBOUND);
              },
          ]
      ],
 ]

foreach($model->getBehavior('galleryBehavior')->getImages() as $image) {
    echo Html::img($image->getUrl('medium'));
}