Неопределенное свойство файла при выполнении загрузки

У меня есть проблемы с Symfony 2 загрузки. Я делаю менеджер слайд-шоу, и я могу загрузить новый слайд (с файлом изображения), но свойство $ файл моего класса «Слайд-шоу» не распознается во время загрузки!

Я следовал этому руководству , и я использую обратные вызовы в жизни доктрина.

Вот мой класс:

id;
    }

    /**
     * Set file
     *
     * @param file $file
     */
    public function setFile($file)
    {
        $this->file = $file;
    }

    /**
     * Get file
     *
     * @return file 
     */
    public function getFile()
    {
        return $this->file;
    }

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

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

    /**
     * Set local
     * 
     * @param string $locale
     */
    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;
    }

    // Others getter and setter methods not shown in this paste ...

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

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

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

    /**
     * getUploadDir of slideshow
     */
    public function getUploadDir()
    {
        return '/uploads/slideshow/'.$this->createdAt->format("Y/m/d");
    }

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

    /**
     * @ORM\PostPersist()
     * @ORM\PostUpdate()
     */
    public function upload()
    {
        if (null !== $this->file) {
            $this->setPath(uniqid().'.'.$this->file->guessExtension());
        }

        if (null === $this->file) {
            return;
        }

        if (!is_dir($this->getUploadRootDir())) {
            mkdir($this->getUploadRootDir(), 777, true);
        }

        $this->file->move($this->getUploadRootDir(), $this->path);

        unset($this->file);
    }

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

Теперь, когда загружается, вы можете увидеть мою ошибку:

Примечание: undefined Свойство: Sybio \ AppBundle \ Entity \ SlideShow :: $ файл в /home/sybio/www/games/src/sybio/appbundle/entity/slideshow.php line. 323

Линия, соответствующая методу:

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

, если я изменяю «$ this-> файл» для «$ this-> getFile ()», у меня есть та же ошибка, но она появляется в Gotter из $ файла Отказ

Если я использую Gotter в действии, он работает и возвращает объект загрузки файла. Если я поставлю файл var_dump of $ this-> в методе установотера, а затем "выйти;", он тоже работает!

И, как видите, мой класс как учебник !!

У любого решения?

5
задан Sybio 10 September 2011 в 13:20
поделиться