vria / enhanced-file
Symfony表单的增强文件类型
1.0.2
2016-05-08 21:14 UTC
Requires
- php: >=5.5.9
- symfony/expression-language: >=3.0
- symfony/form: >=3.0
- symfony/framework-bundle: >=3.0
- twig/twig: ~1.23|~2.0
Requires (Dev)
- phpunit/phpunit: 4.8.*
This package is not auto-updated.
Last update: 2024-09-14 19:36:38 UTC
README
具有额外功能的Symfony表单文件类型
- 如果文件之前已上传,则显示下载链接
- 如果上传新文件,则可以删除之前上传的文件
##安装
使用 Composer,运行
composer require vria/enhanced-file
将VRiaNoDiacriticBundle添加到您的应用程序内核
// app/AppKernel.php public function registerBundles() { return array( // ... new VRia\Bundle\EnhancedFileBundle\VRiaEnhancedFileBundle(), ); }
##使用
在Symfony 3中,您应使用
$form = $this->createFormBuilder() ->add('file', EnhancedFileType::class, $options) ...
而在Symfony ~2.3中
$form = $this->createFormBuilder() ->add('file', 'enhanced_file', $options) ...
$options
是一个数组,包含增强的表单字段选项
directory_path
- 放置文件的物理目录。例如$this->get('kernel')->getRootDir() . '/../web/upload/'
。 必需public_directory_path
- 从您的公共目录(通常是/web
)到文件目录的路径。例如'/upload/'
。 必需delete_previous_file
- 是否删除之前上传的文件。默认值为true
因此,完整的定义可以是
$form = $this->createFormBuilder() ->add('file', EnhancedFileType::class, array( 'label' => 'Curriculum vitae', 'directory_path' => $this->get('kernel')->getRootDir() . '/../web/upload/', 'public_directory_path' => '/upload/', 'required' => false ))