neonbug /meexo-gallery

Meexo CMS 的画廊包

1.0.2 2022-10-23 19:19 UTC

README

在其他模块中将画廊图片用作数据类型

  1. 打开您的模块模型(例如 /Models/Shop.php)并实现 \Neonbug\Gallery\Traits\GalleryImagesTraitInterface 接口。

    示例

<?php namespace App\Packages\Shop\Models;

class Shop extends \Neonbug\Common\Models\BaseModel implements \Neonbug\Gallery\Traits\GalleryImagesTraitInterface {
	
	public $gallery_images = []; // keys are id languages, then field names
	public static function getTableNameForGalleryImages() { return 'shop'; } // from GalleryImagesTraitInterface
	public static function getUploadsFolderNameForGalleryImages() { return 'shop'; } // from GalleryImagesTraitInterface
  1. 在您的模块的 ServiceProvider 中使用 trait \Neonbug\Gallery\Traits\GalleryImagesTrait(例如 /Providers/ServiceProvider.php)。

    示例

<?php namespace App\Packages\Shop\Providers;

class ServiceProvider extends \Neonbug\Common\Providers\BaseServiceProvider {
	
	use \Neonbug\Gallery\Traits\GalleryImagesTrait;
  1. 在您的模块的配置文件中添加一个或多个字段,类型为 gallery_admin::add_fields.gallery_images(例如 /config/shop.php)。

    示例

<?php
return [
    ...
    'add' => [
        [
            'name' => 'images', 
            'type' => 'gallery_admin::add_fields.gallery_images', 
            'value' => '', 
        ], 
    ], 
    ...
];
  1. 要加载图片,请使用 GalleryRepository 上的 getImages 方法。它返回一个 GalleryImage 对象的集合。

    示例

<?php
...
$images = App::make('\Neonbug\Gallery\Repositories\GalleryRepository')->getImages(
	'shop', // table name
	'images', // field name
	$item->id_shop, // item id
	null // language id (or null, if this field is language independent)
);
  1. 要在视图中显示图片,请使用 GalleryImage 上的 getPath 方法来获取图片路径。

    示例

@foreach ($images as $image)
    <?php
	$image_path = $image->getPath(
        'shop', // table name
        'images', // 
        $item->id_shop, // item id
        0 // language id (or 0, if this field is language independent)
    );
	if (!file_exists($image_path))
	{
		continue;
	}
    ?>
    <img src="{!! Croppa::url($image_path, 420, 280) !!}" />
@endforeach

许可协议

MIT 许可协议 下可用。