kematjaya / download-bundle
Installs: 142
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/kematjaya/download-bundle
Requires
- defuse/php-encryption: ^2.2
- doctrine/orm: ^2.7|^3.0
- symfony/config: ^4.0|^5.0|^5.1
- symfony/dependency-injection: ^4.0|^5.0|^5.1
- symfony/form: ^4.0|^5.0|^5.1
- symfony/framework-bundle: ^4.0|^5.0|^5.1
- symfony/http-kernel: ^4.0|^5.0|^5.1
- symfony/mime: ^4.0|^5.0|^5.1
- symfony/routing: ^4.0|^5.0|^5.1
- symfony/twig-bundle: ^4.0|^5.0|^5.1
Requires (Dev)
- phpunit/phpunit: ^6.4
- symfony/browser-kit: ^4.0|^5.0|^5.1
README
-
install
composer require kematjaya/download-bundle -
update config/bundles.php
Kematjaya\DownloadBundle\DownloadBundle::class => ['all' => true] -
create file config/packages/kmj_download.yml
download: upload_dir: '%kernel.project_dir%/public/uploads' encrypt: key: ~ # encrypt key -
import routing config/routes/annotations.yaml
kmj_download: resource: '@DownloadBundle/Resources/config/routing.xml' -
using template in twig config/packages/twig.yaml
twig: form_themes: [ '@Download/upload_theme.html.twig' ] -
implement to entity e.g. App\Entity\Person
namespace App\Entity; use Kematjaya\DownloadBundle\Entity\DownloadInterface; /** * @ORM\Table(name="person") */ class Person implements DownloadInterface { /** * @ORM\Column(type="string", length=255, nullable=true) */ private $images; public function getImages(): ?string { return $this->images; } public function setImages(?string $images): self { $this->images = $images; return $this; } public static function getPaths():array { return [ 'getImages' => 'person' // 'getImages' is function where contain file name, and 'person' is path where file uploaded inside 'upload_dir' (part 3) ]; } } -
dont forget to add upload file type in Form class e.g App\Form\PersonType
namespace App\Form; use App\Entity\Person; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\OptionsResolver\OptionsResolver; class PersonType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('images', FileType::class); } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'data_class' => Person::class, ]); } }