https://github.com/burzum/cakephp-file-storage/blob/3.0/docs/Home.md
我有两张桌子
ProductStylesTable.php和ProductStyleImagesTable.php,它们扩展了ImageStorageTable,ImageStorageTable连接到使用迁移工具创建的sql中的FileStorage表。
上传工作正常。
// 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);
}
棒极了,ProductStyleImages正在监听上传方法,并将其放置在适当的文件夹中。我希望这对删除也能起到同样的作用。
所以我打电话给
//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();
}
我得到一个错误,删除必须与接口兼容。因此,为了避免这种冲突,我将函数重命名为"removeImage"。它可以移除行,但侦听器不会拾取它。我查看了ImageStorageTable.php和FileStorageTable.php。我看到了afterDelete方法。但我不确定如何触发它们,因为我不知道如何配置我的删除方法来匹配接口。
我删除错了,是这样
$entity = $this->get($fileStorageID);
$result = $this->delete($entity);