symfony 2上传一个bundle



我为symfony 2使用OneUp捆绑包,方法的侦听器类从不调用

//service.yml
amd_picture.uploadListener:
    class: AmdPictureBundleServicesUploadListener
    arguments: ["@doctrine.orm.entity_manager"]
    tag:
      - {name: kernel.event_listener, event: oneup_uploader.post_chunk_upload, method: onUpload}

监听器类实现了onUpload方法和相应的事件,它是要监听的正确事件吗???

class UploadListener {
   private $doctrine;
   public function __construct($doctrine) {
      $this->doctrine = $doctrine;
   }
   public function onUpload(PostChunkUploadEvent $event) {
       //source code
   }
}

前端模板的srcipt

<script>
  YUI().use('uploader', function(Y) {
    var uploader = new Y.Uploader(
            {
                multipleFiles: true,
                uploadURL: "{{ oneup_uploader_endpoint('gallery') }}",
                width: "300px",
                height: "60px"
            }).render("#fileupload");
</script>

我不明白为什么onUpload方法从不被调用?

您必须在use语句中使用postPersientEvent:

use OneupUploaderBundleEventPostPersistEvent;

小校正:

//service.yml
amd_picture.uploadListener:
   class: AmdPictureBundleServicesUploadListener
   arguments: ["@doctrine.orm.entity_manager"]
      tag:
        - {name: kernel.event_listener, event: oneup_uploader.post_persist, method:     onUpload}

不是标记。Is:

tags:
        - {name: kernel.event_listener, event: oneup_uploader.post_persist, method:     onUpload}

YUI3 Uploader无法将文件分割成块,因此OneupUploaderBundle的YUI3控制器也不支持它。这意味着不存在将被调度的post_chunk_upload,并且永远不会调用您的EventListener

如果您想在文件成功上传后进行处理,请尝试收听捆绑包手册中描述的PostPersistEvent

//service.yml
amd_picture.uploadListener:
    class: AmdPictureBundleServicesUploadListener
    arguments: ["@doctrine.orm.entity_manager"]
    tag:
        - {name: kernel.event_listener, event: oneup_uploader.post_persist, method:     onUpload}

并且一定要将PostPersistEvent对象传递给侦听器。

use OneupUploaderBundleEventPostPersistEvent;
class UploadListener {
    public function onUpload(PostPersistEvent $event)
    {
        //...
    }
}

相关内容

  • 没有找到相关文章