kematjaya/upload-bundle

3.4.5 2023-11-14 07:52 UTC

README

  1. installation
composer require kematjaya/upload-bundle
  1. add to bundles.php
...
Kematjaya\UploadBundle\UploadBundle::class => ['all' => true]
...
  1. Update schema database
php bin/console doctrine:schema:update --force
  1. import route
## config/routes/annotations.yaml
...
upload:
    resource: '@UploadBundle/Resources/routes/all.yml'
...
  1. Set Upload directory
// config/packages/upload.yaml
upload:
    uploads_dir: '%kernel.project_dir%/public/uploads'
  1. use KmjFileType in form
...
use Kematjaya\UploadBundle\Type\KmjFileType;
...
...
public function buildForm(FormBuilderInterface $builder, array $options)
{
    ...
    $builder->add('attachment', KmjFileType::class, [
      'label' => 'attachment'
    ]);
    
    // or add additional directory inside upload dir
    $builder->add('attachment', KmjFileType::class, [
      'label' => 'attachment',
      'additional_path' => 'foo'
    ]);
    ...
}
  1. update your database schema
php bin/console doctrine:schema:update --force
  1. add form theme in config/packages/twig.yml
twig:
    form_themes: [
        '@Upload/fields.html.twig',
        ......
    ]