Created
February 9, 2014 16:13
-
-
Save petrjirasek/8901323 to your computer and use it in GitHub Desktop.
VichUploader saving problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vich_uploader: | |
| db_driver: orm | |
| mappings: | |
| product_image: | |
| uri_prefix: /images/products | |
| upload_destination: %kernel.root_dir%/../web/upload | |
| namer: vich_uploader.namer_uniqid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $photo1 = new Photo(); | |
| $photo1->setLabel("Photo 1"); | |
| $photo1->setImage(new File(__DIR__ . "/../Files/image1.png")); | |
| $em->persist($photo1); | |
| $em->flush(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace JMShop\CatalogBundle\Entity; | |
| use Doctrine\ORM\Mapping as ORM; | |
| use Gedmo\Mapping\Annotation as Gedmo; | |
| use Symfony\Component\HttpFoundation\File\File; | |
| use Symfony\Component\Validator\Constraints as Assert; | |
| use Vich\UploaderBundle\Mapping\Annotation as Vich; | |
| use JsonSerializable; | |
| /** | |
| * @ORM\Table() | |
| * @ORM\Entity() | |
| * @Vich\Uploadable | |
| */ | |
| class Photo | |
| { | |
| /** | |
| * @var integer | |
| * | |
| * @ORM\Column(name="id", type="integer") | |
| * @ORM\Id | |
| * @ORM\GeneratedValue(strategy="AUTO") | |
| */ | |
| private $id; | |
| /** | |
| * @var string | |
| * | |
| * @ORM\Column(name="name", type="string", length=255, nullable=true) | |
| */ | |
| private $label; | |
| /** | |
| * @Assert\File( | |
| * maxSize="1M", | |
| * mimeTypes={"image/png", "image/jpeg", "image/pjpeg"} | |
| * ) | |
| * @Vich\UploadableField(mapping="product_image", fileNameProperty="imageName") | |
| * | |
| * @var File $image | |
| */ | |
| protected $image; | |
| /** | |
| * @ORM\Column(type="string", length=255, name="image_name") | |
| * | |
| * @var string $imageName | |
| */ | |
| protected $imageName; | |
| /** | |
| * @ORM\ManyToOne(targetEntity="Product", inversedBy="photos") | |
| * @ORM\JoinColumn(name="product_id", referencedColumnName="id") | |
| */ | |
| private $product; | |
| /** | |
| * @Gedmo\Timestampable(on="create") | |
| * @ORM\Column(name="createdAt", type="datetime") | |
| */ | |
| private $createdAt; | |
| /** | |
| * @ORM\Column(name="updatedAt", type="datetime") | |
| * @Gedmo\Timestampable(on="update") | |
| */ | |
| private $updatedAt; | |
| /** | |
| * @return int | |
| */ | |
| public function getId() | |
| { | |
| return $this->id; | |
| } | |
| /** | |
| * @return string | |
| */ | |
| public function getLabel() | |
| { | |
| return $this->label; | |
| } | |
| /** | |
| * @param string $label | |
| */ | |
| public function setLabel($label) | |
| { | |
| $this->label = $label; | |
| } | |
| /** | |
| * @return mixed | |
| */ | |
| public function getProduct() | |
| { | |
| return $this->product; | |
| } | |
| /** | |
| * @param mixed $product | |
| */ | |
| public function setProduct($product) | |
| { | |
| $this->product = $product; | |
| } | |
| /** | |
| * @return \Symfony\Component\HttpFoundation\File\File | |
| */ | |
| public function getImage() | |
| { | |
| return $this->image; | |
| } | |
| /** | |
| * @param \Symfony\Component\HttpFoundation\File\File $image | |
| */ | |
| public function setImage($image) | |
| { | |
| $this->image = $image; | |
| } | |
| /** | |
| * @return string | |
| */ | |
| public function getImageName() | |
| { | |
| return $this->imageName; | |
| } | |
| /** | |
| * @param string $imageName | |
| */ | |
| public function setImageName($imageName) | |
| { | |
| $this->imageName = $imageName; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment