bprs/asset-bundle

此包已被弃用且不再维护。未建议替代包。

为您的应用程序提供简单资源。上传图片、视频等,并将其与实体链接

维护者

详细信息

github.com/SrgSteak/BPRSAssetBundle

安装: 234

依赖项: 0

建议者: 0

安全: 0

星级: 1

关注者: 1

分支: 0

类型:symfony-bundle

此包尚未发布版本,可用的信息不多。


README

为您的应用程序提供简单资源。上传图片、视频等,并将其与实体链接

安装

在您的 composer.json 文件中,将以下内容添加到 "require"

composer require bprs/asset-bundle

"require": {
    "bprs/asset-bundle": "^2.0"

在 AppKernel 中激活此包

$bundles = array(
    ...
    new Bprs\AssetBundle\BprsAssetBundle()
    ...
);

以及您选择的文件系统管理器

$bundles = array(
    ...
    new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle()
    ...
);

$bundles = array(
    ...
    new Oneup\FlysystemBundle\OneupFlysystemBundle()
    ...
);

配置

BPRSAssetBundle 位于 OneupUploaderBundle 之上,这提供了最大的灵活性。

Gaufrette

# Example config
bprs_asset:
    class: "AppBundle\Entity\Asset"
    adapters:
        gallery:
            url: "https:///MyProject/web/uploads"
            path: "/opt/local/apache2/htdocs/MyProject/web/uploads"
            
knp_gaufrette:
    adapters:
        gallery:
            local:
                directory: %kernel.root_dir%/../web/uploads
                create: true

    filesystems:
        gallery:
            adapter: gallery
            
oneup_uploader:
    mappings:
        gallery:
            frontend: blueimp
            storage:
                type: gaufrette
                filesystem: gaufrette.gallery_filesystem
                sync_buffer_size: 100M

Flysystem

使用

关系

资源可以是独立的,也可以是一对一、一对多或多对多关系。为了保持这种灵活性,资源实体现在是 MappedSuperclass。您的资源现在可以包含任何需要的属性,并且您的数据库保持干净。

BaseAsset 已经定义了几个有用的信息

  • createdAt (自动设置)
  • updatedAt (自动设置并更新)
  • filekey (唯一的文件名)
  • adapter (存储在文件系统适配器的名称)
  • mimetype (例如 image/jpeg, quicktime/video)
  • filesize (以字节为单位)
  • md5 (哈希)
  • name (原始文件名)
<?php

// Example asset childclass

namespace Your\Name\Space;

use Doctrine\ORM\Mapping as ORM;
use Bprs\AssetBundle\Entity\Asset as BaseAsset;
/**
 * Extends the MappedSupperclass from the BprsAssetBundle
 *
 * @ORM\Entity
 * @ORM\Table()
 */
class Asset extends BaseAsset
{
    // Whatever your Asset needs
    //...
    //...
}
?>

表单

BPRSAssetBundle 包含一个自定义 Formtype、Datatransformer 以及所需的 JavaScript。假设您有一个与多个资源链接的实体

// form builder
public function buidlForm(FormBuilderInterface $builder, array $options) {
    $builder->add('assets', 'assets'); 
}

或只是一个资源

// form builder
public function buidlForm(FormBuilderInterface $builder, array $options) {
    $builder->add('asset', 'asset'); 
}

然后是视图

    {{ form_start(form) }}    
        {% include "BprsAssetBundle::upload.html.twig" with {'form': form, 'adapter': 'gallery', 'hidePrevious': true} %}
    {{ form_end(form) }}
    
    {% block stylesheets %}
    {{ parent() }}
    <link href="{{ asset('bundles/bprsasset/css/jquery.fileupload.css') }}" rel="stylesheet" />
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    {# if you don't use the BprsStylBundle, you'll need to include jquery yourself! #}
    {% include "BprsAssetBundle::upload.js.twig" %}    
{% endblock %}

缩略图

此包包含一个方便的缩略图过滤器用于 twig。您只需

# asset|thumb(height,width)
<img src="{{ asset|thumb(720,1280) }}" />

创建并动态显示缩略图。

文件大小和相对路径

<a href="{{ asset|link }}">{{ asset.name|filesize(false) }}</a>

下载和列表

通过以下方式激活路由

#routing.yml

bprs_asset:
    resource: .
    type: bprs_asset
    prefix:   /{_locale}
    requirements:
        _locale:  de|en
    defaults: { _locale: de }

您可以使用安全设置来保护下载。

路径 "bprs_asset_list (页面: 页面)" 列出所有已知资源。
路径 "bprs_asset_download (filekey: filekey)" 允许下载。(您可能需要 xsendfile 来处理大文件)