cześć
dodałem do profilu użytkownika możliwość upload obrazka (avatar), no i pięknie działa. Ale po zalogowaniu się do konta a następnie przekierowaniu -> wywala bład:
Error: Call to a member function move() on a non-objectczepia się o linię którą wyszczałkowałem (IMG:
style_emoticons/default/smile.gif) Prosze o pomoc.
Kod klasy User.php
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()); }
Ten post edytował dopelganger 23.09.2015, 13:46:50