2017 © Pedro Peláez
 

symfony-bundle file-bundle

Symfony FileBundle

image

paradise/file-bundle

Symfony FileBundle

  • Monday, June 5, 2017
  • by florianmarical
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Paradise FileBundle

Installing

Attention the template use Gedmo Uploadable !, (*1)

Composer.json, (*2)

"require": {
       ...,
        "paradise/file-bundle": "dev-master"
    },

config.yml, (*3)

twig:
    form_themes:
        - 'FileBundle:Form:fields.html.twig'

Uses

In an entity, (*4)

    /**
     * @var File
     *
     * @ORM\OneToOne(targetEntity="Paradise\FileBundle\Entity\File", cascade={"persist", "remove"})
      @ORM\JoinColumn(name="favicon")
     * @Assert\File(
     *     maxSize = "2M",
     *     mimeTypes = {"image/jpeg", "image/gif", "image/png"},
     *     mimeTypesMessage = "The selected file is not a valid file",
     *     notFoundMessage = "The file was not found on the disk",
     *     uploadErrorMessage = "Error in upload file"
     * )
     */
    private $favicon;

In formType, (*5)

$builder->add('favicon', FileUploadType::class, array('attr' => array('placeholder' => 'Favicon'), 'required' => false, 'path' => true));

If path is true, the picture appears in the render, (*6)

Uses

In a controller for the upload. Attention at the parameter. he is in parameter.yml., (*7)

example: parameters: file: directory: 'uploads/directory', (*8)

$path = $this->getParameter('file')['site_directory'] . $site->getId();
$this->get('ServiceFile')->uploadFile($site->getFavicon(), $path);

The Versions

05/06 2017