1

我正在通过奏鸣曲管理员使用 vich 上传,我可以上传和删除文件我的问题是我无法获取上传的文件信息

我使用 vich 上传器配置“inject_on_load”为真

vich_uploader:
    db_driver: orm # or mongodb or propel or phpcr
    mappings:
        small_image:
            uri_prefix:         /uploads/images/small
            upload_destination: %kernel.root_dir%/../web/uploads/images/small
            namer:              vich_uploader.namer_uniqid
            inject_on_load:     true
            delete_on_update:   true
            delete_on_remove:   true

现在,当我将对象转储到控制器中时,我得到了带有 File Inejcted Proprieties 的对象

Movie {#679 ▼
 -id: 7
 -featureImageFile: -featureImageFile: File {#771 ▼
    path: "C:\wamp/../web/uploads/images/feature"
    filename: "56cd61b786c57.jpg"
    basename: "56cd61b786c57.jpg"
    pathname: "C:\wamp\www\/uploads/images/feature\56cd61b786c57.jpg"
    extension: "jpg"
    realPath: "C:\wamp\www\uploads\images\feature\56cd61b786c57.jpg"
    aTime: 2016-02-24 08:54:30
    mTime: 2016-02-24 08:54:30
    cTime: 2016-02-24 08:54:30
    inode: 0
    size: 173519
    perms: 0100666
    owner: 0
    group: 0
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
    linkTarget: "C:\wamp\...\images\feature\56cd61b786c57.jpg"
   }
 -featureImageName: "56cd61b786c57.jpg"
  #regions: PersistentCollection {#717 ▶}
  #genre: Genre {#739 ▶}
  #language: Language {#745 ▶}
} 

但我在奏鸣曲 postUpdate(movie) 保存钩子中加载文件我没有得到有关文件的信息

public function postUpdate($movie){
    dump($movie); exit;
}

我得到了这个结果

Movie {#679 ▼
 -id: 7
 -featureImageFile: null
 -featureImageName: "56cd61b786c57.jpg"
  #regions: PersistentCollection {#717 ▶}
  #genre: Genre {#739 ▶}
  #language: Language {#745 ▶}
} 

这是我的电影实体类

<?php

namespace Application\NS\AdminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;


/**
 * Movie
 *
 * @ORM\Table(name="movie")
 * @ORM\Entity(repositoryClass="Application\NS\AdminBundle\Repository\MovieRepository")
 * @Vich\Uploadable
 */
class Movie
{



    /**
     * @Vich\UploadableField(mapping="feature_image", fileNameProperty="featureImageName")
     * @var File
     */
    private $featureImageFile;

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

    /**
     * Set featureImageName
     * @param string $featureImageName
     * @return object
     */
    public function setFeatureImageName($featureImageName) {
        $this->featureImageName = $featureImageName;
        return $this;
    }

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

}

这是我的管理课

/**
 * @param FormMapper $formMapper
 */
protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
     ->add('featureImageFile', 'vich_image', array( 'required' => false, 'allow_delete'  => true, 'download_link' => false))
}                

我所缺少的任何人都可以帮助吗?是否有任何替代方法可以将上传的文件信息注入实体对象

4

1 回答 1

0

我们需要手动刷新学说对象以加载更新的属性(vich uploader 通过事件将文件信息注入对象属性)

 $this->getContainer()->get('doctrine.orm.entity_manager')->refresh($movie);
于 2016-02-27T05:51:18.640 回答