2lenet/attachment-bundle
Composer 安装命令:
composer require 2lenet/attachment-bundle
包简介
Attachment
关键字:
README 文档
README
Installation
composer req 2lenet/attachment-bundle
Add to your config/routes.yaml ( no flex reciepe for the moment ).
lle_attachment: resource: "@LleAttachmentBundle/Resources/config/routing/routes.yaml"
Embed controller in a template
{{ render(controller('lle.attachment', {'item': item})) }}
Or with field if you want only an group of attachment
{{ render(controller('lle.attachment', {'item': item, options: {'field': 'pdf'}})) }}
Like that you can use "lle.attachment" action with EasyAdminPlusBundle:
show: title: title.examen.show fields: - { type: 'tab', id: 'documents', label: 'tab.documents', action: 'lle.attachment'}
Or with field if you want only an group of attachment
show: title: title.examen.show fields: - { type: 'tab', id: 'documents', label: 'tab.documents', action: 'lle.attachment', options: {'field': 'pdf'}}
Information: the lle.attachment is a alias of lle.attachment.show.action
Easy use
render the widget for upload:
{{ render_attachment(entity) }}
render the list (ul) for download:
{{ list_attachment(entity) }}
You can use several attachment on the same template
{{ render_attachment(item) }}
{% for examen in item.examens %}
<h3>{{ examen }}</h3>
{{ render_attachment(examen) }}
{% endfor %}
Configurations
with default value
framework: translator: fallbacks: ['fr'] lle_attachment: directory: data/attachment #directory of files is registred show_list: false #show or not show the list of files (table) with uploader widget need_confirm_remove: true #modal for confirm delete or no
Thanks to use
pre load for list of entities:
If you list 20 entities with 20 call of {{ list_attachment(entity) }} you want 1 request not 20:
call
<?php $this->attachmentManager->load(MyEntityClass::class, $ids);
exemple with EasyAdmin
<?php namespace App\EventListener; use App\Entity\Rapport; use Lle\AttachmentBundle\Service\AttachmentManager; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; use Symfony\Component\EventDispatcher\GenericEvent; class RapportSubscriber implements EventSubscriberInterface { private $attachmentManager; public function __construct(AttachmentManager $attachmentManager) { $this->attachmentManager = $attachmentManager; } public static function getSubscribedEvents() { return [ EasyAdminEvents::POST_LIST => 'onPostList', ]; } public function onPostList(GenericEvent $event) { if($event->getArgument('entity')['class'] === Rapport::class){ $ids = []; foreach($event->getSubject()->getCurrentPageResults() as $item){ $ids[] = $item->getId(); } $this->attachmentManager->load(Rapport::class, $ids); } } }
add uploaded file in form
- Add UploadedFileAttachmentInterface with UploadedFileAttachmentTrait at your entity
use Lle\AttachmentBundle\UploadedFileAttachmentInterface; use Lle\AttachmentBundle\UploadedFileAttachmentTrait;
- In your entity form add
$builder->add('uploadedFilesAttachment', FileType::class, ['multiple'=> true]); // or (and) $builder->add('uploadedFileAttachment', FileType::class, ['multiple'=> false]); $builder->add('uploadedFilesAttachmentField'); //optional (default is null)
- Now you have to call addFileByEntity after persist (entity identification have to be create)
$this->attachmentManager->addFileByEntity($entity);
- here an simple exemple with EasyAdmin:
<?php namespace App\EventListener; use Doctrine\ORM\EntityManagerInterface; use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; use Lle\AttachmentBundle\Service\AttachmentManager; use Lle\AttachmentBundle\UploadedFileAttachmentInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\GenericEvent; class AttachmentSubscriber implements EventSubscriberInterface { private $attachmentManager; public function __construct(AttachmentManager $attachmentManager){ $this->attachmentManager = $attachmentManager; } public function addFile(GenericEvent $event){ if($event->getSubject() instanceof UploadedFileAttachmentInterface){ $this->attachmentManager->addFileByEntity($event->getSubject()); } } public static function getSubscribedEvents() { return [ EasyAdminEvents::POST_PERSIST => 'addFile', EasyAdminEvents::POST_UPDATE => 'addFile' ]; } }
- if you want you can defin the default filed in entity
public function getUploadedFilesAtachmentField(): ?string{ return 'uploaded'; }
- For validation use Symfony validator annotations or validator in form (Advice: if you use validator annotation create your own Trait)
2lenet/attachment-bundle 适用场景与选型建议
2lenet/attachment-bundle 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 6.68k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 06 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「attachment」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 2lenet/attachment-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 2lenet/attachment-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 2lenet/attachment-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Implement a polymorphic morphMany relationship for managing attachments within Filament
Extension for file uploading and attaching to the models
Extension for file uploading and attaching to the models
Laravel Eloquent file attachment solution
Yii2-attachments is a module and set of functionality to add attachments to a model in a generic way
Utils for content builder style attachments, using group attachment widget.
统计信息
- 总下载量: 6.68k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-06