2

我将 OneUp 包用于 symfony 2,方法的侦听器类从不调用

//service.yml
amd_picture.uploadListener:
    class: Amd\PictureBundle\Services\UploadListener
    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
   }
}

前端模板的脚本

<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 方法?

4

3 回答 3

2

你必须在你使用语句中使用 postPersitentEvent :

use Oneup\UploaderBundle\Event\PostPersistEvent;
于 2013-11-28T15:28:39.220 回答
2

小修正:

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

不是标签。是:

tags:
        - {name: kernel.event_listener, event: oneup_uploader.post_persist, method:     onUpload}
于 2014-10-09T07:20:39.157 回答
1

YUI3 -Uploader无法将文件拆分成块,因此OneupUploaderBundleYUI3Controller也不支持它。这意味着没有post_chunk_upload将被调度的并且EventListener永远不会调用你的。

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

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

并确保将PostPersistEvent对象传递给侦听器。

use Oneup\UploaderBundle\Event\PostPersistEvent;

class UploadListener {
    public function onUpload(PostPersistEvent $event)
    {
        //...
    }
}
于 2013-11-28T17:48:13.307 回答