Cytat(memory @ 24.09.2015, 09:14:58 )

Podaj całą zawartość klasy
<?php
namespace Test\UserBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints
as Assert;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="Test_users")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string $firstname
*
* @ORM\Column(name="firstname",type="string",length=30)
*/
protected $firstname;
/**
* @var string $image
* @Assert\File( maxSize = "15k", mimeTypes = {"image/jpeg", "image/jpg", "image/gif", "image/png", "image/bmp"}, mimeTypesMessage = "Prosze wybrać plik graficzny!")
* @ORM\Column(name="image", type="string", length=255)
*/
protected $image;
/**
* Set firstname
*
* @param string $firstname
* @return User
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Sets image.
*
* @param UploadedFile $image
*/
public function setImage(UploadedFile $image = null)
{
$this->image = $image;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Get firstname
*
* @return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Get image.
*
* @return UploadedFile
*/
public function getImage()
{
return $this->image;
}
public function __construct()
{
parent::__construct();
// your own logic
}
// Callbacks - upload ***********************************************************************
public function getFullImagePath() {
return null === $this->image ? null : $this->getUploadRootDir(). $this->image;
}
protected function getUploadRootDir() {
// the absolute directory path where uploaded documents should be saved
return $this->getTmpUploadRootDir().$this->getId()."/";
}
protected function getTmpUploadRootDir() {
// the absolute directory path where uploaded documents should be saved
return __DIR__ . '/../../../../web/images/uploads/';
}
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function uploadImage() {
// the file property can be empty if the field is not required
if (null === $this->image) {
return;
}
if(!$this->id){
$this->image->move($this->getTmpUploadRootDir(), $this->image->getClientOriginalName());
}else{
$this->image->move($this->getUploadRootDir(), $this->image->getClientOriginalName());
}
$this->setImage($this->image->getClientOriginalName());
}
/**
* @ORM\PostPersist()
*/
public function moveImage()
{
if (null === $this->image) {
return;
}
if(!is_dir($this->getUploadRootDir())){ mkdir($this->getUploadRootDir()); }
copy($this->getTmpUploadRootDir().$this->image, $this->getFullImagePath()); unlink($this->getTmpUploadRootDir().$this->image); }
/**
* @ORM\PreRemove()
*/
public function removeImage()
{
unlink($this->getFullImagePath()); rmdir($this->getUploadRootDir()); }
}
zaznacze że zmieniając na:
setImage(UploadedFile $image = null)
w ogóle nie działa upload ani dodawanie do bazy nazwy pliku, wcześniejsza wersja działała