vria / enhanced-file
Enhanced file type for Symfony forms
Installs: 261
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Type:symfony-bundle
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-10-26 20:26:23 UTC
README
File type for Symfony forms with additional functionality:
- if file has been previously uploaded, the download link is rendered
- previously uploaded file can be deleted if new one is uploaded
##Installation
Using Composer, run:
composer require vria/enhanced-file
Add the VRiaNoDiacriticBundle to your application kernel:
// app/AppKernel.php public function registerBundles() { return array( // ... new VRia\Bundle\EnhancedFileBundle\VRiaEnhancedFileBundle(), ); }
##Use
In Symfony 3 you should use:
$form = $this->createFormBuilder() ->add('file', EnhancedFileType::class, $options) ...
While in Symfony ~2.3:
$form = $this->createFormBuilder() ->add('file', 'enhanced_file', $options) ...
$options
is an array of options form FormType Field enlarged with:
directory_path
- physycal directory to put files. E.g.$this->get('kernel')->getRootDir() . '/../web/upload/'
. Requiredpublic_directory_path
- path from your public directory (often/web
) to directory with files. E.g.'/upload/'
. Requireddelete_previous_file
- whether to delete previously uploaded file. Default value istrue
So, the complete definition could be:
$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 ))