Faizan
Faizan

Reputation: 383

Empty $this->data in afterDelete callback?

I want to delete the associated file of a record after deleting the record. But I get $this->data empty in after delete callback method.

Upvotes: 2

Views: 695

Answers (3)

Maxime
Maxime

Reputation: 43

It is actually not empty. It's just a mistake in the docs I think. Try this:

// 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();
}

Upvotes: 0

vkovic
vkovic

Reputation: 804

I agree, but the docs are little bit unclear:

// 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();
}

Upvotes: 1

HaroonAbbasi
HaroonAbbasi

Reputation: 126

you have to store the file name in variable before delete operation.

Upvotes: 2

Related Questions