我正在使用dustin10 10/VichUploaderBundle上传图片。
我正在使用Gregwar/ImageBundle来调整图像的大小。
dustin10 10/VichUploaderBundle有一个POST_UPLOAD事件。我怎么触发这个事件。我读过这些文档,但没有说明如何触发这些事件。
https://github.com/dustin10/VichUploaderBundle/blob/master/Event/Events.php
我们的计划是在上传后用ImageBundle调整图片的大小。
S
发布于 2015-10-13 14:16:37
您不能“触发”事件,它已经触发了这里
/**
* Checks for file to upload.
*
* @param object $obj The object.
* @param string $fieldName The name of the field containing the upload (has to be mapped).
*/
public function upload($obj, $fieldName)
{
$mapping = $this->getMapping($obj, $fieldName);
// nothing to upload
if (!$this->hasUploadedFile($obj, $mapping)) {
return;
}
$this->dispatch(Events::PRE_UPLOAD, new Event($obj, $mapping));
$this->storage->upload($obj, $mapping);
$this->injector->injectFile($obj, $mapping);
$this->dispatch(Events::POST_UPLOAD, new Event($obj, $mapping));
}你能做的就是处理这件事,我认为这就是你所指的。您可以通过创建一个如概述的这里那样的侦听器来做到这一点。侦听器将监听POST_UPLOAD事件,如下所示:
# app/config/services.yml
services:
app_bundle.listener.uploaded_file_listener:
class: AppBundle\EventListener\UploadedFileListener
tags:
- { name: kernel.event_listener, event: vich_uploader.post_upload, method: onPostUpload }您的侦听器类将为vich uploader事件键入提示,如下所示:
// src/AppBundle/EventListener/AcmeRequestListener.php
namespace AppBundle\EventListener;
use Symfony\Component\HttpKernel\HttpKernel;
use Vich\UploaderBundle\Event\Event;
class UploadedFileListener
{
public function onPostUpload(Event $event)
{
$uploadedFile = $event->getObject();
// your custom logic here
}
}https://stackoverflow.com/questions/33104245
复制相似问题