Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在CakePHP中将变量从beforeDelete传递到afterDelete()_Php_Cakephp - Fatal编程技术网

在CakePHP中将变量从beforeDelete传递到afterDelete()

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

我想在数据库中的记录被删除后删除一个文件。 因为我使用了相关模型中的一些数据来构建到映像的路径,所以我需要在beforeDelete()中获取这些数据


如何正确访问
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']);       
}