douhai9043 2015-08-25 16:17
浏览 41
已采纳

CakePHP 3 Filestorage插件触发ImageProcessingListener以删除版本

https://github.com/burzum/cakephp-file-storage/blob/3.0/docs/Home.md

I have two tables

ProductStylesTable.php and ProductStyleImagesTable.php which extends ImageStorageTable which is connect to my FileStorage Table in my sql that was created with the migration tool.

Upload works fine.

// ProductStylesController.php 

 public function upload($product_style_id = null) {
      $this->ProductStyles->ProductStyleImages->upload( $product_style_id, $entity)




//ProductStyleImagesTable.php

class ProductStyleImagesTable extends ImageStorageTable { 

//initialize code...

 public function upload($product_style_id, $entity) {

    $entity = $this->patchEntity($entity, [
        'adapter' => 'Local',
        'model' => 'ProductStyles',
        'foreign_key' => $product_style_id,
    ]);
    return $this->save($entity);

}

Awesome, ProductStyleImages is listening for the upload method and places it in the appropriate folder. I was hoping this would work the same for delete.

So I called

  //ProductStylesController.php
  $this->ProductStyles->ProductStyleImages->delete($fileStorage_id)

  //In my ProductStyleImagesTable.php
  public function delete($fileStorageID = null) {

    //deleting the row, hoping for ImageProcessingListener to pick it up?
    $FileStorageTable = TableRegistry::get('FileStorage');
    $query = $FileStorageTable->query();
    $query->delete()
        ->where(['id' => $fileStorageID ])
        ->execute();


}

I get an error that delete must be compatible with the interface. So to avoid this conflict I renamed my function to 'removeImage'. It works in removing the row but the Listener isn't picking it up. I looked in ImageStorageTable.php and FileStorageTable.php. I see the afterDelete methods. But i'm unsure how to trigger them since i'm unsure how to configure my delete methods to match the interface.

  • 写回答

1条回答 默认 最新

  • duan198727 2015-08-27 17:48
    关注

    I deleted wrong, it is this way

    $entity = $this->get($fileStorageID);
    $result = $this->delete($entity);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 配置FPT报错,该如何处理
  • ¥15 请大家看一下这个代码咋写,一点思路都没有,最好能做一下,不要伪代码,有偿
  • ¥15 有偿请人帮写个安卓系统下禁止装软件及禁止拷入文件的程序
  • ¥100 用 H.265 对音视频硬编码 (CUDA)
  • ¥20 mpich安装完成后出问题
  • ¥15 stm32循迹小车代码问题
  • ¥15 输入一堆单词,使其去重输出
  • ¥15 qc代码,修改和添加东西
  • ¥50 Unity的粒子系统使用shadergraph(内置管线)制作的一个顶点偏移shader,但是粒子模型移动时,顶点也会偏移
  • ¥15 如何用python处理excel的数据(极值标准化)