anime-db / form-type-image-bundle
图片上传表单类型
dev-master
2016-05-25 14:36 UTC
Requires
- php: >=5.4.0
- symfony/symfony: >=2.8.0
Requires (Dev)
Suggests
- sonata-project/admin-bundle: Allows upload images in SonataAdminBundle
This package is auto-updated.
Last update: 2024-09-15 20:22:39 UTC
README
图片上传表单类型
安装
使用 Composer 非常简单,运行
composer require anime-db/form-type-image-bundle
将 FormTypeImageBundle 添加到您的应用程序内核中
// app/AppKernel.php public function registerBundles() { return array( // ... new AnimeDb\Bundle\FormTypeImageBundle\AnimeDbFormTypeImageBundle(), // ... ); }
配置
默认配置
anime_db_cache_time_keeper: web_path: '/upload/' # Upload images directory: %kernel.root_dir%/../web/upload/ authorized: true # Only authorized users can upload images constraint: files_limit: 10 # Limiting the number of simultaneous file upload max_size: null # Max file size. Example: 2M min_width: 0 # Minimum image width min_height: 0 # Minimum image height max_width: 0 # Maximum image width max_height: 0 # Maximum image height
添加表单模板
twig: form: resources: [ 'AnimeDbFormTypeImageBundle:Form:fields.html.twig' ]
为 SonataDoctrineORMAdminBundle 添加表单模板
sonata_doctrine_orm_admin: templates: form: [ 'AnimeDbFormTypeImageBundle:Form:sonata_admin_fields.html.twig' ]
用法
use AnimeDb\Bundle\FormTypeImageBundle\Form\Type\ImageType; use AnimeDb\Bundle\FormTypeImageBundle\Form\Type\ImageCollectionType; $form = $this ->createFormBuilder() ->add('cover', ImageType::class) ->add('covers', ImageCollectionType::class);