Last active
August 29, 2015 14:20
-
-
Save roniemicro/8e87914a576cf85b151b to your computer and use it in GitHub Desktop.
Doctrine Uploadable extention uses
This file contains 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
... | |
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), | |
... |
This file contains 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
.... | |
"stof/doctrine-extensions-bundle": "~1.1@dev", | |
..... |
This file contains 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
stof_doctrine_extensions: | |
default_locale: en_US | |
uploadable: ~ | |
class: | |
uploadable: ...\UploadableListener | |
orm: | |
default: | |
uploadable: true |
This file contains 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
$em->persist($entity); | |
..... | |
$uploadableManager = $this->get('stof_doctrine_extensions.uploadable.manager'); | |
$uploadableManager->markEntityToUpload($entity, $entity->getFile()); | |
.... | |
$em->flush(); |
This file contains 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 Setting\Bundle\ContentBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\HttpFoundation\File\UploadedFile; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use Gedmo\Mapping\Annotation as Gedmo; | |
/** | |
* Entity | |
* | |
* @ORM\Table() | |
* @ORM\Entity(repositoryClass="Setting\Bundle\ContentBundle\Entity\SiteSliderRepository") | |
* @Gedmo\Uploadable(pathMethod="getUploadRootDir", allowOverwrite=false, appendNumber=true) | |
*/ | |
class Entity | |
{ | |
/** | |
* @var integer | |
* | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
*/ | |
private $id; | |
/** | |
* @var string | |
* @Gedmo\UploadableFileName | |
* @ORM\Column(name="path", type="string", length=255, nullable=true) | |
*/ | |
private $path; | |
/** | |
* @Assert\File(maxSize="") | |
*/ | |
protected $file; | |
/** | |
* Sets file. | |
* | |
* @param UploadedFile $file | |
*/ | |
public function setFile(UploadedFile $file = null) | |
{ | |
$this->file = $file; | |
} | |
/** | |
* Get file. | |
* | |
* @return UploadedFile | |
*/ | |
public function getFile() | |
{ | |
return $this->file; | |
} | |
/** | |
* @return string | |
*/ | |
public function getPath() | |
{ | |
return $this->path; | |
} | |
/** | |
* @param string $path | |
*/ | |
public function setPath($path) | |
{ | |
$this->path = $path; | |
} | |
protected function getUploadRootDir() | |
{ | |
return "file_path"; | |
} | |
/** | |
* @return int | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @param int $id | |
*/ | |
public function setId($id) | |
{ | |
$this->id = $id; | |
} | |
} |
This file contains 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 ....; | |
use Gedmo\Uploadable\UploadableListener as BaseListener, | |
Gedmo\Uploadable\FileInfo\FileInfoInterface; | |
class UploadableListener extends BaseListener | |
{ | |
public function moveFile(FileInfoInterface $fileInfo, $path, $filenameGeneratorClass = false, $overwrite = false, $appendNumber = false, $object) | |
{ | |
$info = parent::moveFile($fileInfo, $path, $filenameGeneratorClass, $overwrite, $appendNumber, $object); | |
$info['fileName'] = basename($info['filePath']); | |
return $info; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment