问题描述
我正在与Sonata管理员&一起使用vich上传我可以上传&删除文件我的问题是我无法获取上载的文件信息
i am using vich upload with sonata admin & i can able to upload & delete filemy issue is i am not able to get uploaded file information
我使用vich上传程序配置"inject_on_load"为真
i used vich uploader config "inject_on_load" as true
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
现在,当我将对象转储到控制器中时,我得到了带有文件非法属性的对象
now when i dump my object in controller i got object with 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)中加载文件,保存钩子,但我没有有关文件的信息
but i am loading file in sonata postUpdate(movie) save hook i am getting no information about file
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))
}
我在想什么,有谁能帮忙?是否有其他方法可以将上传的文件信息注入实体对象
what i am missing can any one help ?is there any alternative method to inject uploaded file information into Entity Object
推荐答案
我们需要手动刷新教义对象以加载更新的属性(vich上传器通过事件将文件信息注入对象属性)
we need to manually refresh the doctrine object to to load updated properties (vich uploader inject file information to object property via events)
$this->getContainer()->get('doctrine.orm.entity_manager')->refresh($movie);
这篇关于Sonata Admin + Vich Upload在加载时无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!