resmedia/yii2-mongo-gallery-manager

用于yii2的mongodb扩展,允许管理图像画廊

安装: 153

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

公开问题: 0

类型:yii2-extension

1.1.0 2021-02-13 11:19 UTC

This package is auto-updated.

Last update: 2024-09-10 18:40:53 UTC


README

这是对https://github.com/zxbodya/yii-gallery-manager的重构

功能

AJAX图像上传 每个图像可选名称和描述 在画廊中排列图像的选项 为每个图像生成具有不同配置的多个版本 拖放功能

依赖关系

Yii2 Twitter bootstrap资源(版本3) Imagine库 JQuery UI(包含在Yii中) 安装:安装此扩展的首选方法是通过composer。

安装

运行

php composer.phar require resmedia/yii2-mongo-gallery-manager

或者运行

composer require resmedia/yii2-mongo-gallery-manager

或者添加到composer

{
  "resmedia/yii2-mongo-gallery-manager": "^1.1.1"
}

使用方法

1) 在需要上传图像的位置添加小部件

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

2) 添加到控制器示例

包括动作和行为

$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
           ]
       ],
    ];
}

3) 添加到模型

'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);
              },
          ]
      ],
 ]

有关图像转换,请参阅imagine文档

4) 获取图像

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

待办事项

在大小过大或过小时发出警报