我正在尝试检查用户尝试删除的记录是否有任何附加记录(在这种情况下是附加费用索赔的用户)。我可以使用 beforeDelete() 模型函数来做到这一点。但是,如果找到记录并且不允许删除,我想传回一条闪存消息,但我只是收到以下错误:
Fatal error: Call to a member function setFlash() on a non-object in...
这是我的代码:
public function beforeDelete($cascade = false) {
$count = $this->ExpenseClaim->find("count", array(
'conditions' => array('ExpenseClaim.user_id' => $this->id)
));
if ($count == 0) {
return true;
} else {
$this->Session->setFlash('User cannot be deleted as they have ' . $count . 'number of expenses claims already in the system');
return false;
}
}
有人能指出我正确的方向吗?
提前致谢