在AfterDelete回调中清空$ this->数据?

时间:2013-11-25 11:43:02

标签: cakephp models

我想在删除记录后删除记录的关联文件。 但是在删除回调方法之后我得到$ this->数据为空。

3 个答案:

答案 0 :(得分:2)

您必须在删除操作之前将文件名存储在变量中。

答案 1 :(得分:1)

我同意,但文档有点不清楚:

// perhaps after deleting a record from the database, you also want to delete
// an associated file
public function afterDelete() {
    $file = new File($this->data['SomeModel']['file_path']);
    $file->delete();
}

答案 2 :(得分:0)

实际上并非空洞。在我认为的文档中,这只是一个错误。试试这个:

// perhaps after deleting a record from the database, you also want to delete
// an associated file
public function afterDelete() {
    $file = new File($this->info['SomeModel']['file_path']);
    $file->delete();
}