kematjaya/upload-bundle

7.0.5 2024-10-24 08:08 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',
        ......
    ]