2012年5月5日 星期六

[Yii] Error handle

PHP 中若遇到一些warning or error ,無法方便的透過try catch處理
Yii提供了error handle:

在config/main.php的components中加入

'errorHandler'=>array(
      'errorAction'=>'base/error',
),
base是controller name
error是action name
可自行替換


我的BaseController如下

public function actionError(){
if($error=Yii::app()->errorHandler->error){
$result["ERRNO"] = "xxxx";
$result["ERRMSG"] = "錯誤訊息";
$this->render('application.views.commonResult', array('result'=>json_encode($result)));
}
}


就可以統一透過actionError處理沒有handle到的錯誤

沒有留言:

張貼留言