it-blaster/attach-file-bundle
Composer 安装命令:
composer require it-blaster/attach-file-bundle
包简介
Symfony2 bundle. The ability to attach files to the form.
关键字:
README 文档
README
Вспомогательный бандл для работы с файлами на сайте. Есть возмжность прикреплять несколько файлов к одной сущности. Есть поддержка языковых версий.
Installation
Добавьте ItBlasterAttachFileBundle в composer.json:
{ "require": { "it-blaster/attach-file-bundle": "dev-master" }, }
Теперь запустите композер, чтобы скачать бандл командой:
$ php composer.phar update it-blaster/attach-file-bundle
Композер установит бандл в папку проекта vendor/it-blaster/attach-file-bundle.
Далее подключите бандл в ядре AppKernel.php:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new ItBlaster\AttachFileBundle\ItBlasterAttachFileBundle(), ); }
В app/config/config.yml необходимо указать путь до класса бихейвора it_blaster_file и подключить шаблон виджета attach_file:
propel:
...
behaviors:
...
it_blaster_file: ItBlaster\AttachFileBundle\Behavior\AttachFileBehavior
twig:
form:
resources:
- 'ItBlasterAttachFileBundle:Form:attach_file_widget.html.twig'
assetic:
bundles:
- 'ItBlasterAttachFileBundle'
В файл app/config/routing.yml необходимо подключить роутинг-файл бандла:
attach_file:
resource: '@ItBlasterAttachFileBundle/Resources/config/routing.yml'
Usage
В файле schema.yml подключите бихейвор it_blaster_file
<table name="example"> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> <column name="title" type="varchar" required="true" primaryString="true" /> <column name="image" type="integer" /> <behavior name="it_blaster_file" > <parameter name="file_columns" value="image" /> </behavior> </table>
В параметре file_columns необходимо указать имя поля изображения. В данном примере этим полем является поле image. Если к сущности необходимо прекреплять несколько файлов, названия полей в параметре file_columns нужно указать через запятую, например:
<table name="example"> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> <column name="title" type="varchar" required="true" primaryString="true" /> <column name="logo" type="integer" /> <column name="sheet" type="integer" /> <behavior name="it_blaster_file" > <parameter name="file_columns" value="logo, sheet" /> </behavior> </table>
Поля файлов должны иметь тип integer
Далее в описании формы редактирования необходимо подключить поле прикрепления файла:
$formMapper ->add('image_file', 'attach_file', array( 'label' => 'Изображение', 'required' => false, 'constraints' => [ new Image([ 'mimeTypes' => [ 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/png' ] ]) ] ));
Обратите внимание, что поле называется не image, а image_file. Это поле image_file и соответствующие методы get и set создал бихейвор AttachFileBehavior, они используются исключительно для формы редактирования.
Use i18n
Если вы используете языковые версии на сайте на основе propel-бихейвора i18n и к каждому переводу необходимо прикреплять файл, то вам необходимо в основной таблице (document) указать параметр i18n, где будет имя поля файла, и в соответствующей таблице с переводами (document_i18n) укзать параметр file_columns, в котором будет то же самое значение поля файла. Пример:
<table name="document" description="Документ"> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> <column name="file_title" type="varchar" required="true" primaryString="true" /> <column name="active" type="boolean" defaultValue="true" /> <column name="download" type="integer"/> <behavior name="i18n"> <parameter name="i18n_columns" value="file_title, active, download" /> </behavior> <behavior name="it_blaster_i18n"> <parameter name="primary_string" value="file_title" /> </behavior> <behavior name="it_blaster_file" > <parameter name="i18n" value="download" /> </behavior> </table> <table name="document_i18n"> <behavior name="it_blaster_file" > <parameter name="file_columns" value="download" /> </behavior> </table>
Далее подключаем виджет attach_file в админ-форме:
$formMapper
->add('DocumentI18ns', new TranslationCollectionType(), [
'label' => false,
'required' => false,
'type' => new TranslationType(),
'languages' => $this->getConfigurationPool()->getContainer()->getParameter('locales'),
'options' => [
'label' => false,
'data_class' => 'Artsofte\MainBundle\Model\DocumentI18n',
'columns' => [
'active' => [
'label' => "Опубликовать",
'type' => 'checkbox',
],
'file_title' => [
'label' => "Имя файла",
'type' => 'text',
'required' => true,
],
'download_file' => array(
'type' => 'attach_file',
'label' => 'Выберите файл',
'maxSize' => '20M',
'options' => [
'sonata_help' => 'Допустимые типы файлов: pdf, doc, docx, zip, jpg, gif, png',
'constraints' => [
new \Symfony\Component\Validator\Constraints\File([
'mimeTypes' => [
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.oasis.opendocument.text',
'application/zip',
'image/gif',
'image/jpeg',
'image/pjpeg',
'image/png'
]
])
]
]
),
]
]
])
;
Credits
It-Blaster it-blaster@yandex.ru
it-blaster/attach-file-bundle 适用场景与选型建议
it-blaster/attach-file-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 161 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「form」 「sluggable」 「type」 「Behavior」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 it-blaster/attach-file-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 it-blaster/attach-file-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 it-blaster/attach-file-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A bundle providing fields for image upload with jquery upload and image cropping with jcrop for symfony2
A simple Symfony bundle that adds boolean form field type.
Provides a HasSlug trait that will generate a unique slug when saving your Laravel Eloquent model.
A PHP Abstract Enum Class
A simple Cake3 plugin to slug fields and find records by slug.
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
统计信息
- 总下载量: 161
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-04