我有一個很大的問題。好吧,我正在嘗試保存在我的Web應用程序中發生的錯誤。例如(只是一個例子),如果我用零來劃分,或者在查詢或類似事件中發生錯誤。所以,我想抓住它並將它保存在數據庫中。但CakePHP的handleError是靜態的,所以我不能使用$ this-> MyModel-> saveError(...)。如何在CakePHP 2.0中用handleError保存錯誤?
在我/app/Lib/AppError.php我有這樣的:
class AppError extends ErrorHandler
{
public $uses = array('Errors.Error');
public static function handleError($code, $description, $file = null, $line = null, $context = null)
{
//This print the error:
echo "Code: ".$code." Description: ".$description." File: ".$file." Line: ".$line."<br>";
//I want to do this, (save to the database):
$this->Error->saveError($code, $description, $file, $line);
}
}
沒有$這個 - >錯誤 - > saveError($代碼,$描述,$文件,$線);它的工作原理,但我不僅要顯示錯誤。 我認爲需要一個例子或類似的東西。請幫幫我。 問候並感謝你。 謝謝... PD:對不起,我的英語,我是英語的學生......
那麼屬性'Error'在哪裏? :) ..並且你爲英語學生而感到難過嗎?嗯好的;) – dbf
那麼,'錯誤'是我的模型。這應該保存在表中的錯誤,但問題是,蛋糕說:當不在對象上下文中使用$ this File:/var/www/industrialProcess/app/Lib/AppError.php – jags1988cr