在CakePHP中将变量从beforeDelete传递到afterDelete()
我想在数据库中的记录被删除后删除一个文件。 因为我使用了相关模型中的一些数据来构建到映像的路径,所以我需要在beforeDelete()中获取这些数据在CakePHP中将变量从beforeDelete传递到afterDelete(),php,cakephp,Php,Cakephp,我想在数据库中的记录被删除后删除一个文件。 因为我使用了相关模型中的一些数据来构建到映像的路径,所以我需要在beforeDelete()中获取这些数据 如何正确访问afterDelete()中的$info数组?您只需在方法范围之外声明此变量即可 private $info; function beforeDelete() { $this->info = $this->find('first', array( 'conditions' => array('Media.i
如何正确访问
afterDelete()
中的$info
数组?您只需在方法范围之外声明此变量即可
private $info;
function beforeDelete() {
$this->info = $this->find('first', array(
'conditions' => array('Media.id' => $this->id),
));
}
function afterDelete() {
unlink(WWW_ROOT . 'img/photos/' . $this->info ['News']['related_id'] . "/" . $this->info ['Media'] ['file']);
}
private $info;
function beforeDelete() {
$this->info = $this->find('first', array(
'conditions' => array('Media.id' => $this->id),
));
}
function afterDelete() {
unlink(WWW_ROOT . 'img/photos/' . $this->info ['News']['related_id'] . "/" . $this->info ['Media'] ['file']);
}