2017-05-12 4 views
0

다른 필드를 변경해야만 문제가 업로드됩니다. 파일 업로드를 선택하면 작동하지 않습니다. 사용 VichUploaderBundle 당신이 파일을 auplad하는 데 도움이 -심포니 FosUserBundle 프로필 사진

/** 
    * @ORM\Entity 
    * @ORM\HasLifecycleCallbacks() 
    * @ORM\Table(name="fos_user") 
    */ 

    class User extends BaseUser 
    { 
    /** 
* @ORM\Id 
* @ORM\Column(type="integer") 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
protected $id; 


/** 
* @ORM\Column(type="string", length=255) 
*/ 
protected $nom; 

/** 
* @ORM\Column(type="string", length=255) 
*/ 
protected $prenom; 




/** 
* @ORM\Column(type="string", length=255, nullable=true) 
*/ 
private $path; 

/** 
* @Assert\File(
*  maxSize = "5M", 
*  mimeTypes = {"image/jpeg", "image/gif", "image/png", "image/tiff"}, 
*  maxSizeMessage = "The maximum allowed file size is 5MB.", 
*  mimeTypesMessage = "Only the file types image are allowed.") 
*/ 
public $file; 


/** 
* @Assert\File(maxSize="2048k") 
* @Assert\Image(mimeTypesMessage="Please upload a valid image.") 
*/ 
protected $profilePictureFile; 

// for temporary storage 
private $tempProfilePicturePath; 

/** 
* @ORM\Column(type="string", length=255, nullable=true) 
*/ 
protected $profilePicturePath; 



public function __construct() 
{ 
    parent::__construct(); 
    // your own logic 
} 






/** 
* Set nom 
* 
* @param string $nom 
* 
* @return User 
*/ 
public function setNom($nom) 
{ 
    $this->nom = $nom; 

    return $this; 
} 

/** 
* Get nom 
* 
* @return string 
*/ 
public function getNom() 
{ 
    return $this->nom; 
} 

/** 
* Set prenom 
* 
* @param string $prenom 
* 
* @return User 
*/ 
public function setPrenom($prenom) 
{ 
    $this->prenom = $prenom; 

    return $this; 
} 

/** 
* Get prenom 
* 
* @return string 
*/ 
public function getPrenom() 
{ 
    return $this->prenom; 
} 



/** 
* @ORM\PrePersist() 
* @ORM\PreUpdate() 
*/ 
public function preUpload() { 
    if (null !== $this->file) { 
     $this->path = uniqid('', true) . '.' . $this->file->guessExtension(); 
    } 
} 

/** 
* @ORM\PostPersist() 
* @ORM\PostUpdate() 
*/ 
public function upload() { 
    if (null === $this->file) { 
     return; 
    } 
    $this->file->move($this->getUploadRootDir(), $this->path); 
    unset($this->file); 
} 

/** 
* @ORM\PostRemove() 
*/ 
public function removeUpload() { 
    if ($this->file == $this->getAbsolutePath()) { 
     unlink($this->file); 
    } 
} 

public function getAbsolutePath() { 
    return null === $this->path ? null : $this->getUploadRootDir() . '/' . $this->path; 
} 

public function getWebPath(){ 
    return null === $this->path ? null : $this->getUploadDir() . '/' . $this->id . '/' . $this->path; 
} 

protected function getUploadRootDir() { 
    return __DIR__ . '/../../../web/' . $this->getUploadDir() . '/' . $this->id; 
} 

protected function getUploadDir() { 
    return 'uploads/users'; 
} 

/** 
* @param string $path 
* @return User 
*/ 
public function setPath($path) { 
    $this->path = $path; 
    return $this; 
} 

/** 
* @return string 
*/ 
public function getPath() { 
    return $this->path; 
} 

/** 
* Set profilePicturePath 
* 
* @param string $profilePicturePath 
* 
* @return User 
*/ 
public function setProfilePicturePath($profilePicturePath) 
{ 
    $this->profilePicturePath = $profilePicturePath; 

    return $this; 
} 

/** 
* Get profilePicturePath 
* 
* @return string 
*/ 
public function getProfilePicturePath() 
{ 
    return $this->profilePicturePath; 
} 

내 재정 FormType ProfileType.php이

class ProfileType extends AbstractType 
{ 
    public function buildForm(FormBuilderInterface $builder, array $options) 
    { 
     $builder->add('nom')->add('prenom')->add('file'); 
    } 

    public function getParent() 
    { 
     return 'FOS\UserBundle\Form\Type\ProfileFormType'; 
    } 

    public function getBlockPrefix() 
    { 
     return 'fos_user_profile_edit'; 
    } 

    public function getName() 
    { 
     return $this->getBlockPrefix(); 
    } 
} 

어떤 도움

답변

0

1과 같이 보입니다 User.php 여기

내 클래스입니다.
2 -이 같은 FOS 양식을 대체 할 양식에 대한 서비스를 만들 수 있습니다

parent::buildForm($builder, $options); 
:

services: 
     class: YouNameSpace\Form\Type\YourFormType 
     arguments: ['%fos_user.model.user.class%'] 
     tags: 
      - { name: form.type, alias: user_registration } 

3가 buildForm 방법 $ 빌더 설정하기 전에 당신이 추가