コード例 #1
0
 /**
  * 显示捕获的错误信息
  * 
  * @param integer $code 错误代码
  * @param string $message 消息
  * @param string $file 文件名
  * @param string $line 错误行号
  */
 public function displayError($code, $message, $file, $line)
 {
     $content = "";
     if (YII_DEBUG) {
         $content = "<h1>PHP Error [{$code}]</h1>\n";
         $content .= "<p>{$message} ({$file}:{$line})</p>\n";
         $content .= '<pre>';
         //
         // 获取trace信息,并忽略前面三个
         //
         $trace = debug_backtrace();
         if (count($trace) > 3) {
             $trace = array_slice($trace, 3);
         }
         foreach ($trace as $i => $t) {
             if (!isset($t['file'])) {
                 $t['file'] = 'unknown';
             }
             if (!isset($t['line'])) {
                 $t['line'] = 0;
             }
             if (!isset($t['function'])) {
                 $t['function'] = 'unknown';
             }
             $content .= "#{$i} {$t['file']}({$t['line']}): ";
             if (isset($t['object']) && is_object($t['object'])) {
                 $content .= get_class($t['object']) . '->';
             }
             $content .= "{$t['function']}()\n";
         }
         $content .= '</pre>';
     } else {
         $content = "<h1>PHP Error [{$code}]</h1>\n";
         $content .= "<p>{$message}</p>\n";
     }
     Yii::log($content, CLogger::LEVEL_ERROR, "miniyun.api");
     if (MUserManager::getInstance()->isWeb() === true) {
         $message = CUtils::transtalte(self::$scene, '', 500);
         header("HTTP/1.1 200 OK");
         $result = array();
         $result["state"] = false;
         $result["code"] = 0;
         $result["message"] = Yii::t('api_message', $message);
         $result["msg"] = Yii::t('api_message', $message);
         $result["msg_code"] = "0";
         $result["data"] = array("d" => false);
     } else {
         MiniUtil::sendResponse(500, $content);
     }
 }