在Symfony / Doctrine中删除记录时执行一些清理 [英] Perform some cleanup when deleting a record in Symfony/Doctrine

查看:459
本文介绍了在Symfony / Doctrine中删除记录时执行一些清理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Symfony 1.4.5与Doctrine

Using Symfony 1.4.5 with Doctrine

我有一个包含上传图像作为列之一的模型 - 创建和更新记录是正确的(使用doSave()方法处理上传和文件的任何更改。)

I have a model which includes an uploaded image as one of the columns - creating and updating the record is fine (using the doSave() method to deal with the upload and any changes to the file).

我遇到的问题是如果记录被删除 - 我想要删除相关的文件以及。但是,在通过文档和Google进行数小时的狩猎之后,我无法找到这个。

The problem I'm having is if the record is deleted - I want it to remove the associated file as well. But I can't find anyway to do this after several hours of hunting through documentation and Google.

有没有办法指定某种删除后的代码? / p>

Is there a way to specify some kind of post-delete code?

推荐答案

最终解决方案:

in / lib / model / doctrine / Image.class.php

in /lib/model/doctrine/Image.class.php

class Image extends BaseImage
{
  public function postDelete()
  {
    $filename = $this->getFilename();

    $filepath = sfConfig::get('sf_upload_dir') . '/' . $filename;
    @unlink($filepath);
  }
}

感谢Sponz上校指示我正确的方向

Thanks to Colonel Sponz for pointing me in the right direction

这篇关于在Symfony / Doctrine中删除记录时执行一些清理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆