donjohn / media-bundle
受 sonata media bundle 启发的简单媒体包
Requires
- php: >=7.1
- ext-fileinfo: *
- ext-gd: *
- ext-mbstring: *
- doctrine/doctrine-bundle: ^1.6
- symfony/filesystem: ^3.4 || ^4.1
- symfony/form: ^3.4 || ^4.1
- symfony/framework-bundle: ^3.4 || ^4.1
- symfony/security-bundle: ^3.4 || ^4.1
- symfony/templating: ^3.4 || ^4.1
- symfony/twig-bundle: ^3.4 || ^4.1
- symfony/validator: ^3.4 || ^4.1
- twig/twig: ^1.28 || ^2.0
Suggests
- api-platform/core: for the awesome api feature
- liip/imagine-bundle: to get filters feature and more for your images
- oneup/uploader-bundle: for the awesome upload of big files feature
- dev-master
- 3.4.7
- 3.4.6
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.9
- 3.3.8
- 3.3.7
- 3.3.5
- 3.3.4
- 3.2.7
- 3.2.6
- 3.2.3
- 3.1.1
- 3.0.6
- 3.0.5
- 2.5.2
- 2.4.3
- 2.3.2
- 2.2.3
- 2.1.1
- 1.5.3
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/express-4.18.2
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/terser-4.8.1
- dev-dependabot/npm_and_yarn/eventsource-1.1.1
- dev-dependabot/npm_and_yarn/url-parse-1.5.10
- dev-dependabot/npm_and_yarn/follow-redirects-1.14.8
- dev-dependabot/npm_and_yarn/ajv-6.12.6
- dev-dependabot/npm_and_yarn/tar-4.4.19
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/browserslist-4.16.6
- dev-dependabot/npm_and_yarn/hosted-git-info-2.8.9
- dev-dependabot/npm_and_yarn/ssri-6.0.2
- dev-dependabot/npm_and_yarn/y18n-3.2.2
- dev-dependabot/npm_and_yarn/elliptic-6.5.4
- dev-dependabot/npm_and_yarn/ini-1.3.7
- dev-dependabot/npm_and_yarn/http-proxy-1.18.1
- dev-dependabot/npm_and_yarn/websocket-extensions-0.1.4
- dev-dependabot/npm_and_yarn/acorn-6.4.1
- dev-dev
This package is auto-updated.
Last update: 2024-08-30 01:39:33 UTC
README
感谢 Sonata,它启发了这个包。
安装
Composer
composer require donjohn/media-bundle
最小配置
创建一个新的类,并扩展 Donjohn\MediaBundle\Media
namespace YourBundle\Entity; use Donjohn\MediaBundle\Model\Media as BaseMedia; /** * @ORM\Table() * @ORM\Entity() */ class YourMedia extends BaseMedia { /** * @var integer * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="IDENTITY") */ protected $id; }
LiipImagineBundle
将此添加到您的 config.yml
liip_imagine: filter_sets: full: quality: 100 thumbnail: quality: 75 filters: auto_rotate: ~ thumbnail: { size: [120, 120], mode: outbound }
有关 liip 过滤器配置,请参阅 LiipImagineBundle 配置
可选配置
更改上传文件的文件夹
donjohn_media: upload_folder: /AnotherFolder liip_imagine: resolvers: default: web_path: cache_prefix: AnotherFolder/cache
限制上传文件大小
donjohn_media: file_max_size: 500M
提供商
可用提供商
- image
- file
用法
要在 twig 中插入媒体,请使用具有可选过滤器名称的块(在 liip_imagine.filter_sets 部分),如果没有提供过滤器名称,则默认为 'reference' 过滤器。它将返回带有任何过滤器或后处理的原始上传媒体。
{% media mediaObject, '<filter>' %}
您还可以向媒体渲染传递 class/width/height/alt 选项
{% media mediaObject, '<filter>' with {class: 'classwanted class2wanted', alt: 'title', width: '200px', height: '50px'} %}
表单类型
有一个 Donjohn\MediaBundle\Form\Type\MediaType
$builder->add(<fieldName>, MediaType::class, ['media_class'=> YourEntity::class] );
提供商选项默认值为 null。猜测器将尝试动态检测每个文件的最佳提供商,除非您定义了选项。默认猜测是 'file'。
将 'allow_delete' 选项设置为 false,如果您不想允许从实体中删除媒体。它将删除表单中的取消链接复选框。
将 'create_on_update' 选项设置为 true,如果您不希望在上传文件时更新当前媒体,而是创建一个新的媒体。旧的一个不会被删除。
如果您想上传媒体集合,请将 multiple 设置为 true。
$builder->add(<fieldName>, MediaType::class, ['media_class' => YourEntity::class, 'multiple' => true ] );
OneupUploader
对于非常大的文件,该包包括 Fine Uploader 功能,归功于 OneUpUploaderBundle。
$builder->add(<fieldName>, MediaType::class, , ['media_class' => YourEntity::class, 'fine_uploader' => true, 'multiple' => <true|false> ] );
不要忘记安装 fineuploader (bower/npm/...) 并将其 css/js 包含在您的布局中(如有必要,请修复路径)。
将 OneupUploaderBundle 添加到您的 AppKernel.php
new Oneup\UploaderBundle\OneupUploaderBundle(),
并在 config.yml 中添加
# Read the documentation: https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md oneup_uploader: chunks: storage: directory: "%kernel.cache_dir%/uploader/chunks" mappings: donjohn_media: namer: Donjohn\MediaBundle\Uploader\Naming\OriginalNamer use_orphanage: true frontend: fineuploader
您可以更改上传的块大小或用于渲染 fineuploader 框架的模板
donjohn_media: chunk_size: 50M #default fine_uploader_template: YourFineUploaderTempalte.twig.html
自定义 MediaProvider
要实现自己的提供商,扩展 BaseProvider 并重新定义抽象函数。
自动装配应该可以完成工作...
Api platform
该包与 APIPlatform 兼容。