开发者

libxml_get_errors custom error handler

Hi i've create a module that build a form from a valid xml, after form submission it rebuild an xml and validate it against an xsd schema. if the form have not been compiled correctly, it return to the form with all the error messages get by libxml_get_errors. the problem is that libxml_get_err开发者_JS百科ors doesn't generate user friendly error messages. is there a way to extend the error handler to produce simpler and more user friendly error messages?

if (!$doc->schemaValidate($schema_riferimento)) 
{ 
  $errors = libxml_get_errors(); 
  foreach ($errors as $error) 
  { 
    array_push($global_errors, $error->message); 
    log_message('debug', "Errore di validazione: ".$error->message); 
  } 
}


I would just create a hash in which you keep friendly error messages, keyed by the error code.

For instance:

$friendly_errors = array(
                       '0' => 'One friendly error message',
                       '1' => 'Another friendly error message
                   );
$friendly_error_message = $friendly_errors[$error->code];
log_message('debug', $friendly_error_message);

Simple.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜