Commit 50f7f9ba authored by Mat's avatar Mat

Installation et configuration initiale de VichUploaderBundle

pour uploader des images, cfr
http://symfony.com/doc/current/bundles/EasyAdminBundle/integration/vichuploaderbundle.html
parent 28104b46
......@@ -21,6 +21,7 @@ class AppKernel extends Kernel
new APIBundle\APIBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
new Vich\UploaderBundle\VichUploaderBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
......
......@@ -9,6 +9,7 @@ imports:
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: fr
app.path.legume_images: /uploads/images/legumes
framework:
#esi: ~
......@@ -83,3 +84,11 @@ fos_user:
fos_js_routing:
routes_to_expose:
- api_legume_*
# VichUploaderBundle Configuration
vich_uploader:
db_driver: orm
mappings:
legume_images:
uri_prefix: '%app.path.legume_images%'
upload_destination: '%kernel.root_dir%/../web/uploads/images/legumes'
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "8327078eb619a89d058b5cd1f6620a89",
"content-hash": "bddd0ec40e25816f1e7988b1f6a2d09c",
"packages": [
{
"name": "composer/ca-bundle",
......@@ -2784,6 +2784,89 @@
],
"time": "2018-03-20T04:25:58+00:00"
},
{
"name": "vich/uploader-bundle",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/dustin10/VichUploaderBundle.git",
"reference": "09c0f0f805f7dce07c6642548344158a1c7faed6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dustin10/VichUploaderBundle/zipball/09c0f0f805f7dce07c6642548344158a1c7faed6",
"reference": "09c0f0f805f7dce07c6642548344158a1c7faed6",
"shasum": ""
},
"require": {
"jms/metadata": "^1.5",
"php": "^5.5|^7.0",
"symfony/asset": "^2.3|^3.0",
"symfony/dependency-injection": "^2.3|^3.0",
"symfony/finder": "^2.2|^3.0",
"symfony/framework-bundle": "^2.3|^3.0",
"symfony/property-access": "^2.5|^3.0",
"symfony/security": "^2.3|^3.0",
"symfony/templating": "^2.3|^3.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.6",
"doctrine/mongodb-odm": "^1.0",
"doctrine/orm": "^2.2.3",
"ext-sqlite3": "*",
"knplabs/knp-gaufrette-bundle": "^0.3",
"matthiasnoback/symfony-dependency-injection-test": "^0.7",
"mikey179/vfsstream": "^1.2",
"oneup/flysystem-bundle": "^1.0",
"phpunit/phpunit": "^5.6",
"symfony/browser-kit": "^2.3|^3.0",
"symfony/css-selector": "^2.3|^3.0",
"symfony/dom-crawler": "^2.3|^3.0",
"symfony/form": "^2.3|^3.0",
"symfony/twig-bridge": "^2.3.10|^3.0",
"symfony/twig-bundle": "^2.3|^3.0",
"symfony/validator": "^2.3|^3.0",
"symfony/yaml": "^2.0.5|^3.0"
},
"suggest": {
"doctrine/doctrine-bundle": "~1.6",
"doctrine/mongodb-odm-bundle": "*",
"doctrine/orm": "^2.2.3",
"doctrine/phpcr-odm": "~1.0",
"knplabs/knp-gaufrette-bundle": "~0.3",
"ocramius/proxy-manager": "To have the Gaufrette with Doctrine adapter",
"symfony/yaml": "^2.0.5",
"willdurand/propel-eventdispatcher-bundle": "~1.2"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": {
"psr-4": {
"Vich\\UploaderBundle\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Dustin Dobervich",
"email": "ddobervich@gmail.com"
}
],
"description": "Ease file uploads attached to entities",
"homepage": "https://github.com/dustin10/VichUploaderBundle",
"keywords": [
"file uploads",
"upload"
],
"time": "2017-07-11T09:11:07+00:00"
},
{
"name": "willdurand/jsonp-callback-validator",
"version": "v1.1.0",
......
......@@ -3,12 +3,15 @@
namespace PotageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* Legume
*
* @ORM\Table(name="legume")
* @ORM\Entity(repositoryClass="PotageBundle\Repository\LegumeRepository")
* @Vich\Uploadable
*/
class Legume
{
......@@ -77,6 +80,27 @@ class Legume
*/
private $prixUnitaire;
/**
* @ORM\Column(type="datetime")
* @var \DateTime
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=255)
* @var string
*/
private $image;
/**
* @Vich\UploadableField(mapping="legume_images", fileNameProperty="image")
* @var File
*/
private $imageFile;
/**
*
*/
......@@ -286,4 +310,33 @@ class Legume
{
return $this->prixUnitaire;
}
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
// VERY IMPORTANT:
// It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
if ($image) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
}
public function getImageFile()
{
return $this->imageFile;
}
public function setImage($image)
{
$this->image = $image;
}
public function getImage()
{
return $this->image;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment