也许你可以阅读这篇关于让 Gedmo Uploadable 与 Sonata Admin 一起工作的帖子
我认为您必须punk_ave.file_uploader
在管理课程中通过该服务:
acme.admin.demo:
class: Acme\DemoBundle\Admin\DemoAdmin
arguments: [~, Acme\DemoBundle\Entity\Demo, SonataAdminBundle:CRUD, @punk_ave.file_uploader]
tags:
- {name: sonata.admin, manager_type: orm, group: demo, label: demo}
calls:
- [ setTranslationDomain, [SonataAdminBundle]]
并更改您的DemoAdmin
班级以管理上传:
class DemoAdmin extends Admin
{
/**
* File uploader
*/
private $fileUploader = null;
/**
* Constructor
*/
public function __construct($code, $class, $baseControllerName, $fileUploader = null)
{
parent::__construct($code, $class, $baseControllerName);
$this->fileUploader = $fileUploader;
}
// ...
public function prePersist($object)
{
$this->manageUploads($object);
}
public function preUpdate($object)
{
$this->manageUploads($object);
}
/**
* Mannger uploads
* @param Demo $object
*/
private function manageUploads($object)
{
if ($object->getId()->getFile()) {
$this->fileUploader->syncFiles(...);
}
}
}
我真的不知道这是否会奏效,但这就是我试图让它发挥作用的方式......