可能是你可以看到這篇文章關於getting Gedmo Uploadable working with 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(...);
}
}
}
我真的不知道這是否會工作,但這就是我試圖讓它工作的方式...
是的,我試圖按照你分享的鏈接......但我不確定「教程」的結束......我得到一個錯誤「調用成員函數get()on一個非對象「..它引用這一行:$ uploadableManager = $ this-> container-> get('stof_doctrine_extensions.uploadable.manager');任何想法?我的services.yml看起來不錯,數據庫也是.. – daneczech