johnproza / yii2-gallery
图片画廊
dev-master
2019-04-29 11:35 UTC
Requires
- yiisoft/yii2: ~2.0.0
- yiisoft/yii2-bootstrap4: @dev
- yiisoft/yii2-imagine: ~2.1.0
This package is auto-updated.
Last update: 2024-09-29 04:43:27 UTC
README
具有react前端的图片画廊
安装
安装此扩展的首选方法是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist johnproza/yii2-gallery "*"
或者
"johnproza/yii2-gallery": "*"
将以下内容添加到您的 composer.json
文件的 require 部分中。
用法
在使用之前,您必须准备数据库
php yii migrate --migrationPath=@vendor/johnproza/yii2-gallery/migrations
模块设置
将以下内容插入您的配置文件中
'modules' => [ 'news' => [ 'class' => 'oboom\gallery\Module', ], ]
模型使用
将以下内容插入您的模型文件中(例如行为)
public function behaviors() { return [ [ 'class' => 'oboom\gallery\behaviors\AttachGallery', 'mainPathUpload'=>Yii::$app->params['uploadPath'].'/uploads', 'mode'=>'multiple', // mode of upload ("single" or "multiple") 'type' => 'news', // type of gallery (may be have a different string value) 'thumbSize'=>[ 'x'=>600, 'y'=>480 ] // size of thumbSize ], ]; }
参数/路径设置
将参数插入您的 params-local.php 文件以正确工作
return [ ...... 'uploadPath' => '/server/path/to/frontend/web', 'webUrl' => [ 'back' => 'http://admin.yourwebsite.com', 'front' => 'http://yourwebsite.com', ] ];
小部件使用
将以下内容插入您的视图文件中以上传图片
use oboom\gallery\widgets\GalleryWidgets; ..... ..... <?= GalleryWidgets::widget([ 'model'=>$items, // model 'type'=>'news', // type of gallery (may be have a different string value) 'max'=>5, //max upload files 'params'=>[ 'aspectRatio'=>[16,9], 'type'=>'single', // mode of upload ("single" or "multiple") 'className'=>'avator-img' // css classname for custom stylization ], ]); ?>
将以下内容插入您的视图文件中以输出图片
use oboom\gallery\widgets\GalleryWidgets; ..... ..... <?= GalleryWidgets::widget([ 'model'=>$item['item'], // model 'type'=>'news', // type of gallery (may be have a different string value) 'show_main'=>true, // if you want to show main image for model 'params'=>[ 'type'=>'showSingle', // if you want to show one image 'className'=>'image' ], ]); ?>
将以下内容插入您的视图文件中以输出图片到您的自定义视图
use oboom\gallery\widgets\GalleryWidgets; ..... ..... <?= GalleryWidgets::widget([ 'model'=>$item['item'], // model 'type'=>'news', // type of gallery (may be have a different string value) 'template'=>"@app/themes/base/views/dev/gallery", // path to your view 'show_main'=>true, // if you want to show main image for model 'params'=>[ 'type'=>'data', // if you want to show all images 'className'=>'image' ], ]); ?> ... custom view <?if (!empty($data)):?> <ul> <?foreach ($data as $item) :?> <li> <a href="<?=Yii::$app->params['webUrl']['front'].$item->path;?>"> <img src = "<?=Yii::$app->params['webUrl']['front'].$item->thumb_path;?>" <?= $className!=null ? "class=".$className : false ;?> /> </a> </li> <?endforeach;?> </ul> <?endif;?>